CheckBox column for DataGrid and add full Select, select All button, set 0 button on table header

Source: Internet
Author: User

To add an event to a checkbox on a DataGrid column header
private void Dgdinfo_itemcreated (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (E.item.itemtype = = Listitemtype.header)
{
String Columns = e.item.cells[24]. Text;
if (columns== "Inerp")
{
Label LBL = new label ();
Lbl.id= "LBL";
LbL. text= "Inerp";
E.ITEM.CELLS[24]. Controls.Add (LBL);

CheckBox chk = new checkbox ();
Chk.id= "CHK";
E.ITEM.CELLS[24]. Controls.Add (CHK);
}
}
}

Select All button
private void Butall_click (object sender, System.EventArgs e)
{
System.Web.UI.WebControls.CheckBox CheckBox;
if (butall.text== "All selected")
{
foreach (DataGridItem datagriditem in Dg_list. Items)
{
checkbox= (checkbox) Datagriditem.findcontrol ("CheckBox2");
Checkbox.checked=true;
}
butall.text= "Total elimination";
}
Else
{
foreach (DataGridItem datagriditem in Dg_list. Items)
{
checkbox= (checkbox) Datagriditem.findcontrol ("CheckBox2");
Checkbox.checked=false;
}
butall.text= "all election";
}
}
0 button
private void Cancel_click (object sender, System.EventArgs e)
{
System.Web.UI.WebControls.TextBox text;
System.Web.UI.WebControls.CheckBox CheckBox;
foreach (DataGridItem datagriditem in Dg_list. Items)
{
checkbox= (checkbox) Datagriditem.findcontrol ("CheckBox2");
if (checkbox.checked==true)
{
text= (TextBox) Datagriditem.findcontrol ("TextBox2");
Text. text= "0";
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.