C# – Get data from gridview row on button click event

asp.netcgridview

I have grid view in which there are image buttons, I want to access grid view data on button click event of that particular row but dont know how to get those values on button click event. Image button is inside template field of gridview.

Best Answer

You can get it in the RowCommand event of the gridview.

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Edit")
    {
        e.CommandArgument // Return Primary key
        GridViewRow row = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
        row.Cells[0].///
        row.Cells[1].///
        ................
    }
}
Related Topic