Skip to content

Instantly share code, notes, and snippets.

@pranabmitra
Created March 1, 2012 10:36
Show Gist options
  • Save pranabmitra/1948977 to your computer and use it in GitHub Desktop.
Save pranabmitra/1948977 to your computer and use it in GitHub Desktop.
Get Value from Gridview in Gridview RowCommand Event
<asp:TemplateField HeaderText="Account No">
<ItemTemplate>
<asp:Label ID="lblAccountNo" runat="server" Text="<%# Bind('ReceivedItemInfo_AccountNo') %>"></asp:Label>
<asp:HiddenField ID="hdnIsFlag" Value="<%# Bind('ReceivedItemInfo_IsFlag') %>" runat="server" />
<asp:HiddenField ID="hdnPreviousState" Value="<%# Bind('ReceivedItemInfo_PreviousState') %>" runat="server" />
</ItemTemplate>
</asp:TemplateField>
protected void gridViewReceivedInfo_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
HiddenField hdnPreviousState = (HiddenField)row.Cells[1].FindControl("hdnPreviousState");
string previousState = hdnPreviousState.Value;
}
@mahendrajale
Copy link

Thanks for solution,
Even we can optimize it as
string previousState = ((HiddenField)((GridViewRow)(((Button)e.CommandSource).NamingContainer)).FindControl("hdnPreviousState")).Value;

@clulloa83
Copy link

muchas gracias!
Thank you too much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment