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.
2 Answers
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].///
................
}
}
Comments
protected void grdList_RowEditing(object sender, GridViewEditEventArgs e)
{
int test_reg_Id = Convert.ToInt32(grdList.DataKeys[e.NewEditIndex].Values[0]);
string query = "select * from test_reg where Id=" + test_reg_Id + "";
query += Session["test_reg_Id"].ToString();
dtable = con.sqlSelect(query);
txt_id.Text = dtable.Rows[0][0].ToString();
txtuname.Text = dtable.Rows[0][1].ToString();
txtpass.Text = dtable.Rows[0][2].ToString();
ddlcountry.SelectedItem.Text = dtable.Rows[0][3].ToString();
}