private void Delete()
{
foreach (GridViewRow row in this.GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox cbk = row.Cells[0].FindControl("CheckBox1") as CheckBox;
if (cbk.Checked)
{
using (SqlConnection sqlcnn = new SqlConnection(str))
{
SqlCommand sqlcmm = sqlcnn.CreateCommand();
sqlcmm.CommandText = "delete topic where id=@id";
sqlcmm.Parameters.Add("@id", SqlDbType.Int).Value = row.Cells[1].Text;
sqlcnn.Open();
int a = sqlcmm.ExecuteNonQuery();
if (a > 0)
Response.Write("删除成功");
}
this.BindStudent();
}
}
}
}
GridView中删除 CheckBox 选择的一行的内容
最新推荐文章于 2012-12-03 16:02:03 发布