Add a clearly selected CheckBox control on the DataGrid header (transfer)

xiaoxiao2021-03-06  53

From: http://blog.9cbs.net/lihonggen0/Archive/2004/08/13/74202.aspx

Add a clear-selected Checkbox control on the DataGrid header

Copyright Notice: 9CBS is this BLOG managed service provider. If this paper involves copyright issues, 9CBS does not assume relevant responsibilities, please contact the copyright owner directly with the article Author.

Very simple method, use JS implementation:

page:

< / Headertemplate>

Headertext = "Department"> Background code:

private void dgUserList_PreRender (object sender, System.EventArgs e) {foreach (DataGridItem item in dgUserList.Controls [0] .Controls) {if (item.ItemType == ListItemType.Header) {CheckBox chkAll = (CheckBox) item.FindControl ( "chkAll"); System.Text.StringBuilder strScript = new System.Text.StringBuilder ( "