CheckBox全选或全不选

<ASP:TEMPLATECOLUMN visible="False" sortexpression="demo" headertext="ID"> 
<ITEMTEMPLATE> 
<ASP:LABEL text=’<%# DataBinder.Eval(Container.DataItem, "ArticleID")%>’ runat="server" width="80%" id="lblColumn" /> 
</ITEMTEMPLATE> 
</ASP:TEMPLATECOLUMN> 

<ASP:TEMPLATECOLUMN headertext="选中"> 
<HEADERSTYLE wrap="False" horizontalalign="Center"></HEADERSTYLE> 
<ITEMTEMPLATE> 
<ASP:CHECKBOX id="chkExport" runat="server" /> 
</ITEMTEMPLATE> 
<EDITITEMTEMPLATE> 
<ASP:CHECKBOX id="chkExportON" runat="server" enabled="true" /> 
</EDITITEMTEMPLATE> 
</ASP:TEMPLATECOLUMN> 

后台代码

protected void CheckAll_CheckedChanged(object sender, System.EventArgs e) 

//改变列的选定,实现全选或全不选。 
CheckBox chkExport ; 
if( CheckAll.Checked) 

foreach(DataGridItem oDataGridItem in MyDataGrid.Items) 

chkExport = (CheckBox)oDataGridItem.FindControl("chkExport"); 
chkExport.Checked = true; 


else 

foreach(DataGridItem oDataGridItem in MyDataGrid.Items) 

chkExport = (CheckBox)oDataGridItem.FindControl("chkExport"); 
chkExport.Checked = false; 


你可能感兴趣的:(checkbox)