Reputation: 5459
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.
Upvotes: 0
Views: 11894
Reputation: 52241
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].///
................
}
}
Upvotes: 2
Reputation: 35
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();
}
Upvotes: 0