From: roberta on
Hi! I've show many example but I don't know how to apply solutions to my
code: I've a gridview with a list of records, I'd like using a detail
button, open an ajax modal popup with the detail (for update) of the row
selected

<asp:GridView ID="gvElencoAttivita" runat="server"
AutoGenerateColumns="False" DataKeyNames="Id"
onrowdatabound="gvElencoAttivita_RowDataBound"
ShowFooter="true" AllowSorting="True" CellPadding="8" GridLines="Vertical">
<Columns>
<asp:TemplateField HeaderText="" ItemStyle-Width="30">
<ItemTemplate>
<asp:Button ID="btnCancella"
OnClick="btnCancellaAttivita_Click" IDRiga='<%# Eval("ID") %>'
runat="Server" CausesValidation="False" Text="Cancella" Width="60px"
OnClientClick="return confirm('Cancellare la riga selezionata?');" />

</ItemTemplate>
<ItemStyle Width="30px"></ItemStyle>
</asp:TemplateField>
<asp:BoundField DataField="DescrizioneAttivita"
HeaderText="Descrizione attività" SortExpression="DescrizioneAttivita"/>
<asp:TemplateField HeaderText="DateApp">
<ItemTemplate>
<asp:Label ID="lblDateApp" runat="server" Text='<%#
Eval("DateApp") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="150px"></ItemStyle>
</asp:TemplateField>

</Columns>

</asp:GridView>
From: Alexey Smirnov on
On May 11, 10:06 am, roberta <r...(a)tis.it> wrote:
> Hi! I've show many example but I don't know how to apply solutions to my
> code: I've a gridview with a list of records, I'd like using a detail
> button, open an ajax modal popup with the detail (for update) of the row
> selected
>
> <asp:GridView ID="gvElencoAttivita" runat="server"
> AutoGenerateColumns="False" DataKeyNames="Id"
> onrowdatabound="gvElencoAttivita_RowDataBound"
> ShowFooter="true" AllowSorting="True" CellPadding="8" GridLines="Vertical">
>          <Columns>
>              <asp:TemplateField HeaderText="" ItemStyle-Width="30">
>                  <ItemTemplate>
>                      <asp:Button ID="btnCancella"
> OnClick="btnCancellaAttivita_Click" IDRiga='<%# Eval("ID") %>'
> runat="Server" CausesValidation="False" Text="Cancella" Width="60px"
> OnClientClick="return confirm('Cancellare la riga selezionata?');" />
>
>                   </ItemTemplate>
>              <ItemStyle Width="30px"></ItemStyle>
>              </asp:TemplateField>
>              <asp:BoundField DataField="DescrizioneAttivita"
> HeaderText="Descrizione attività" SortExpression="DescrizioneAttivita"/>
>              <asp:TemplateField HeaderText="DateApp">
>                  <ItemTemplate>
>                      <asp:Label ID="lblDateApp" runat="server" Text='<%#
> Eval("DateApp") %>'></asp:Label>
>                  </ItemTemplate>
>              <ItemStyle Width="150px"></ItemStyle>
>              </asp:TemplateField>
>
>         </Columns>
>
>      </asp:GridView>


You need to get the gridviewrow from the sender to get the datakey

For example

protected void LinkButton_Click(object sender, EventArgs e)
{
LinkButton MyLink = sender as LinkButton;
GridViewRow row = (GridViewRow)MyLink.NamingContainer;
int id = (int)this.PMAGrid.DataKeys[row.RowIndex].Value;
....
// show the modal popup
this.mdlPopup.Show();

where mdlPopup is a name of your ModalPopupExtender