//给DataGrid列头上的CheckBox添加事件
private void dg_list_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Header)
{
CheckBox cbk=(CheckBox)e.Item.FindControl("CheckBox1");
cbk.CheckedChanged+=new EventHandler(butAll_Click);
}
}
//全选按钮
private void butAll_Click(object sender, System.EventArgs e)
{
System.Web.UI.WebControls.CheckBox CheckBox;
if(butAll.Text=="全选")
{
foreach(DataGridItem DataGridItem in dg_list.Items)
{
CheckBox=(CheckBox)DataGridItem.FindControl("CheckBox2");
CheckBox.Checked=true;
}
butAll.Text="全消";
}
else
{
foreach(DataGridItem DataGridItem in dg_list.Items)
{
CheckBox=(CheckBox)DataGridItem.FindControl("CheckBox2");
CheckBox.Checked=false;
}
butAll.Text="全选";
}
}
//置零按钮
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";
}
}
}