Aspx page:
Copy codeThe Code is as follows:
<Script src = "Jquery1.7.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ('# Checkbox1'). click (function (){
If ($ ('# Checkbox1'). is (': checked ')){
$ ('Td input'). attr ('checked', true );
}
Else {$ ('td input'). attr ('checked', false );}
})
$ ('# Checkbox2'). click (function (){
$ ('Td input'). each (function (){
$ (This). attr ('checked ',! $ (This). attr ('checked '))
})
})
})
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Input id = "Checkbox1" type = "checkbox"/> select <input id = "Checkbox2" type = "checkbox"/> invert <asp: Button
ID = "Button1" runat = "server" Text = "delete" onclick = "button#click"/>
<Asp: GridView ID = "GridView1" runat = "server" AutoGenerateColumns = "False">
<Columns>
<Asp: TemplateField HeaderText = "select">
<ItemTemplate>
<Asp: CheckBox ID = "CheckBox3" runat = "server"/>
</ItemTemplate>
</Asp: TemplateField>
<Asp: BoundField DataField = "Id" HeaderText = "no."/>
<Asp: BoundField DataField = "NewsTitle" HeaderText = "title"/>
<Asp: BoundField DataField = "NewsContent" HeaderText = "news">
<ItemStyle Width = "200px"/>
</Asp: BoundField>
<Asp: BoundField DataField = "NewsCreator" HeaderText = "creator"/>
<Asp: BoundField DataField = "CreateTime" HeaderText = "Creation Time"/>
</Columns>
</Asp: GridView>
</Div>
</Form>
Backend cs files:
Copy codeThe Code is as follows:
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
Load ();
}
}
Private void load () // bind
{
Jquery three-layer deletion function. Model. T_News mm = new Model. T_News ();
Jquery three-layer deletion function. BLL. T_News bb = new BLL. T_News ();
String sqlwhere = "Id <25 ";
Ds = bb. GetList (sqlwhere); // obtain the dataset binding
This. GridView1.DataSource = ds;
GridView1.DataBind ();
}
Protected void button#click (object sender, EventArgs e)
{
// Traverse each row
Foreach (GridViewRow item in GridView1.Rows) // remember that gridviewrow is not a datarow
{
CheckBox cb = (CheckBox) item. FindControl ("CheckBox3"); // locate the selected item
If (cb. Checked) // select
{
Jquery three-layer deletion function. BLL. T_News bb = new BLL. T_News ();
If (bb. DeleteList (item. Cells [1]. Text) // call bb. DeleteList (id) to delete
{
Response. Write ("deleted successfully ");
}
Load ();