直接在GridView1加Delete列也可以
SelectCommand="SELECT [StuID], [StuName], [Stupassword] FROM [stuent] "
ConnectionString="<%$ ConnectionStrings:xueshengConnectionString %>" >
如果protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
主要代码是
string strconn = Convert.ToString(ConfigurationManager.ConnectionStrings["sqlconn"]);//sqlconn自己命名
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
string strsql = "delete from customer where CustomID=@customid";//列名改成自己的
SqlCommand cmd = new SqlCommand(strsql, conn);
SqlParameter param = new SqlParameter("@customid", GridView1.DataKeys[e.RowIndex].Value);
cmd.Parameters.Add(param);
}
aspx那边要加OnRowDeleting="GridView1_RowDeleting
捕获行事件,获取数据对应的唯一键
直接操作数据库,cc.mycon.Open()中cc 应该是开启数据库连接sqlcontion