asp.net gridview control Select all, uncheck, delete the implementation of the selected item
1. Add a template column to the GridView control, add a CheckBox control to the column, and add the desired button, as shown in the figure:
2. Select All Events
<span style= "FONT-SIZE:18PX;" >//all
protected void Btn_all_click (object sender, EventArgs e)
{for
(int i = 0; I <= GridView2.Rows.Cou nt-1; i++)
{
checkbox cbox = (checkbox) Gridview2.rows[i]. FindControl ("CheckBox1");
Cbox. Checked = true;
}
} </span>
3, Cancel the event
<span style= "FONT-SIZE:18PX;" >//Cancel
protected void Btn_cancel_click (object sender, EventArgs e)
{for
(int i = 0; I <= gridview2.rows . Count-1; i++)
{
checkbox cbox = (checkbox) Gridview2.rows[i]. FindControl ("CheckBox1");
Cbox. Checked = false;
}
} </span>
4. Anti-election events
<span style= "FONT-SIZE:18PX;" >//Anti-select
protected void Btn_others_click (object sender, EventArgs e)
{for
(int i = 0; I <= gridview2.rows . Count-1; i++)
{
checkbox cbox = (checkbox) Gridview2.rows[i]. FindControl ("CheckBox1");
if (Cbox. Checked = = True)
{
cbox. Checked = false;
}
else
{
Cbox. Checked = true;
}
}
</span>
5. Delete selected items (principle: traverse all the checkbox in the GridView control)
<span style= "FONT-SIZE:18PX;" >//Delete selected
protected void Btn_del_click (object sender, EventArgs e)
{for
(int i = 0; I <= gridview2.rows . Count-1; i++)
{
checkbox cbox = (checkbox) Gridview2.rows[i]. FindControl ("CheckBox1");
if (Cbox. Checked==true)
{
//here performs the delete operation
}
}
}</span>