You should bind the field into the
CommandArgument
of the button.
for example on the gridview, you can have a button like this one:
<asp:TemplateField HeaderText="custom column">
<asp:Button runat="server" CommandArgument='<%# Eval("UserID") %>' OnClick="OnMyButtonClick"/>
</asp:TemplateField>
note this button is on a
TemplateField
. And is using evaluation the UserID into the
CommandArgument
property.
Now in the C# code behind you can do this:
protected void OnMyButtonClick(object sender, EventArgs e)
{
Button b = sender as Button;
if (b!=null)
{
var hey = b.CommandArgument;
}
}
And voila..
Hope it helps.