您好,我是今天上午问您关于girdview后台数据绑定问题的那个~如果绑定后...
发布网友
发布时间:2024-03-28 11:24
我来回答
共1个回答
热心网友
时间:2024-08-15 03:13
首先在GridView属性里面为它的DataKeyNames设置为SoftwareID 然后在RowDeleting事件里添加如下
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sql = "server=.;database=你的数据库;integrated security=sspi;";
SqlConnection conn = new SqlConnection(sql);
string id=GridView1.DataKeys[e.RowIndex].Value.ToString();
string CmdSql="Delete from [你的表] where SoftwareID='"+id+"'";
SqlCommand cmd=new SqlCommand(CmdSql,conn);
try
{
conn.open();
cmd.ExcuteNoneQuery();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
conn.Close();
cmd.Dispose();
}
}