In
Gridview
RowCommand
,
protected void gvScripts_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "IFullView")
{
int index = 0;
string lstrVal = "";
if (e.CommandArgument != "")
{
index = Convert.ToInt32(e.CommandArgument);
lstrVal = gvScripts.DataKeys[index].Value.ToString().Trim();
}
}
}
And in .
aspx
,
I have a column with
ImageButton
. So, when I click this button, I need to get the value of a column (of
SelectedRow
), which is given in
DataKeyNames
in
GridView
,
<asp:GridView ID="gvScripts" runat="server" AutoGenerateColumns="False" OnRowCommand="gvScripts_RowCommand" DataKeyNames="DL_RECID">
<Columns>
<asp:TemplateField HeaderText="" HeaderStyle-HorizontalAlign="center" HeaderStyle-Width="30px">
<ItemStyle CssClass="HRLineCDL" Wrap="true" HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:ImageButton ID="btnIFullView" AlternateText="Full View" runat="server" CommandName="IFullView"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
</ItemTemplate>
</asp:TemplateField>
</Columns>