我有网格视图,其中有图像按钮,我想访问该特定行的按钮点击事件的网格视图数据,但不知道如何在按钮点击事件上获取这些值。图像按钮位于gridview的模板字段内。
答案 0 :(得分:2)
您可以在gridview的RowCommand
事件中获取它。
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].///
................
}
}
答案 1 :(得分:0)
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();
}