e.RowIndex
为5但gridView1.DataKeys.count=0
你能帮助我吗?
protected void gridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
string T10_CodGar = gridView1.DataKeys[e.RowIndex].Values["T10_CodGar"].ToString();
con.Open();
SqlCommand cmd = new SqlCommand("delete from [PUMA2_FINANZIARIAFAMILIARE].[dbo].[TCOR10] where T10_CodGar=" + T10_CodGar, con);
int result = cmd.ExecuteNonQuery();
con.Close();
if (result == 1)
{
loadStores1();
// lblmsg.BackColor = Color.Red;
// lblmsg.ForeColor = Color.White ;
// lblmsg.Text = stor_id + " Deleted successfully....... ";
}
}
catch (Exception ex) { }
}
答案 0 :(得分:1)
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeys(v=vs.110).aspx
的DataKeys文档说
设置DataKeyNames属性时,GridView控件 自动为。中的每一行创建一个DataKey对象 控制....然后将DataKey对象添加到控件中 DataKeys集合。
您需要在GridView上使用合适的值设置DataKeyNames属性,然后才能使用。