runat="server">
<ItemTemplate>
<asp:CheckBox id="chb" runat="server"></asp:CheckBox><%# DataBinder.Eval(Container.DataItem,"id") %>
<%# DataBinder.Eval(Container.DataItem,"mm") %>
</ItemTemplate>
</asp:DataList>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 280px; POSITION: absolute; TOP: 64px" runat="server"
Text="全选"></asp:Button>
<asp:Button id="Button2" style="Z-INDEX: 103; LEFT: 336px; POSITION: absolute; TOP: 64px" runat="server"
Text="delete"></asp:Button>
public void data()
{
SqlConnection con=new SqlConnection("server=.;database=pubs;uid=sa;pwd=123");
SqlDataAdapter sda=new SqlDataAdapter("select * from ta",con);
DataSet ds=new DataSet();
sda.Fill(ds,"jobs");
this.DataList2.DataSource=ds;
this.DataList2.DataKeyField="id";
this.DataList2.DataBind();
}
private void Button1_Click(object sender, System.EventArgs e)
{
foreach(System.Web.UI.WebControls.DataListItem Item in this.DataList2.Items)
{
CheckBox chb=(CheckBox)Item.FindControl("chb");
chb.Checked=true;
}
}
private void Button2_Click(object sender, System.EventArgs e)
{
foreach(System.Web.UI.WebControls.DataListItem Item in this.DataList2.Items)
{
CheckBox chb=(CheckBox)Item.FindControl("chb");
if(chb.Checked==true)
{
string id=this.DataList2.DataKeys[Item.ItemIndex].ToString();
SqlConnection con=new SqlConnection("server=.;database=pubs;uid=sa;pwd=123");
con.Open();
SqlCommand cmd=new SqlCommand("delete from ta where id='"+id+"'",con);
cmd.ExecuteNonQuery();
}
}
data();
}