这是我的绑定代码:
string connection_string = ConfigurationManager.ConnectionStrings["DBC"].ConnectionString;
SqlConnection con = new SqlConnection(connection_string);
con.Open();
SqlDataAdapter dataadapter = new SqlDataAdapter("Select * from stud_table", con);
DataSet ds = new DataSet();
dataadapter.Fill(ds);
CheckBoxList1.DataSource = ds;
CheckBoxList1.DataTextField = "Name";
CheckBoxList1.DataValueField = "Rollno";
CheckBoxList1.DataBind();
con.Open();
按钮代码:
protected void Button2_Click(object sender, EventArgs e)
{
for(int i=0;i<CheckBoxList1.Items.Count ;i++)
{
if (CheckBoxList1.Items[i].Selected == true)
{
CheckBoxList1.Items.RemoveAt(i);
}
}
}
如果我选择该项目并单击删除按钮,它应该从数据库和屏幕中删除。我该怎么做呢?