很简单的方法,就是用js实现:
页面:
AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False">
后台代码:
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(" \n");
if(!Page.IsClientScriptBlockRegistered("checkStatus"))
Page.RegisterClientScriptBlock("checkStatus",strScript.ToString());
chkAll.Attributes.Add("onclick","checkStatus()");
return;
}