Insert a checkbox single selection in the DataGrid header to define it as full selection and implement full selection of the checkbox before each row of data in the entire DataGrid

Source: Internet
Author: User

Write the following in the time when the DataGrid is bound:Code:
If (E. Item. itemtype = listitemtype. header)
{
Checkbox chk = (checkbox) E. Item. findcontrol ("chkallserver ");
// Add a departure event to the checkbox in the header
Chk. checkedchanged + = new eventhandler (chk_checkedchanged );
}

Private void chk_checkedchanged (Object sender, system. eventargs E)
{
Checkbox chk = This. getheadercheckbox (this. datagrid1 );
Foreach (maid I in this. Maid)
{
Checkbox inchk = (checkbox) I. findcontrol ("chkdelserver ");
Inchk. Checked = chk. checked;
}
}
// Get the checkbox object of the question header of the specified DataGrid
Private checkbox getheadercheckbox (DataGrid GRD)
{
Checkbox chk = NULL;
Foreach (maid I in GRD. controls [0]. Controls)
{
If (I. itemtype = listitemtype. header)
{
Chk = (checkbox) I. findcontrol ("chkallserver ");
Break;
}
}
Return chk;
}

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.