Last post Apr 24, 2012 06:22 PM by N_EvilScott
Apr 24, 2012 06:08 PM|Msa|LINK
I have a grid view, which contain a button in each row
I want to do something with the data key (the primary key ) of the grid when I press a button in some row
can I retrieve the data key for used row to use it in my C# code ?
thank you all :)
Apr 24, 2012 06:22 PM|N_EvilScott|LINK
Are you using built in buttons like Select, Edit, Delete? Or are you using a custom button? If you are using your own button then I would just suggest using the Command options.
<asp:GridView ID="MyGridView" runat="server" onrowcommand="MyGridView_RowCommand">
<asp:Button ID="MyCoolButton" runat="server" Text="Click Me To Get ID" CommandName="MyCommand" CommandArgument='<%# Eval("ID") %>' />
// C# Code Behind
protected void MyGridView_RowCommand(object sender, GridViewCommandEventArgs e)
if (e.CommandName == "MyCommand")
int primaryKey = Convert.ToInt32(e.CommandArgument);
// do stuff with your primary key value here.