点击一个checkbox控件,使得Datagrid里的模版里放的checkbox全部选中

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace localhost.模版后台管理
{
 /// <summary>
 /// SkinManage 的摘要说明。
 /// </summary>
 public class SkinManage : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.Button BtnSelectAll;
  protected System.Web.UI.WebControls.Button BtnDel;
  protected System.Web.UI.WebControls.Button BtnSubmit;
  protected System.Web.UI.WebControls.CheckBox CheckBoxSelectAll;
  protected System.Web.UI.WebControls.DataGrid DataGrid2;
  protected bool selected=false;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   // 在此处放置用户代码以初始化页面
   SqlConnection Conn;
   Conn=new SqlConnection("server=localhost;database=Skin;uid=sa;pwd=''");
   Conn.Open();   
   SqlDataAdapter da=new SqlDataAdapter("select Id,Skin_name from SkinBin",Conn);
   DataSet ds=new DataSet();
   da.Fill(ds,"skin");
   da.Fill(ds,"skinall");
//   show_string=ds.Tables["skin"].Rows[0][0].ToString();   
   DataGrid2.DataSource=ds.Tables["skinall"].DefaultView;
   DataGrid2.DataBind();
  }

  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.DataGrid2.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid2_DeleteCommand);
   this.BtnSelectAll.Click += new System.EventHandler(this.BtnSelectAll_Click);
   this.CheckBoxSelectAll.CheckedChanged += new System.EventHandler(this.CheckBoxSelectAll_CheckedChanged);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  private void DataGrid2_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
   try
   {
    SqlConnection Conn;
    Conn=new SqlConnection("server=localhost;database=Skin;uid=sa;pwd=''");
    Conn.Open();
    string Id="";
    Id=e.Item.Cells[2].Text;
    SqlCommand Comm=new SqlCommand("update SkinBin set IsDefault=1 where Id="+Id,Conn);
    Comm.ExecuteNonQuery();
   }
   catch
   {

   }
   Response.Write("<script>alert('模版已更改,请查看用户界面');</script>");

  }

  private void BtnSelectAll_Click(object sender, System.EventArgs e)
  { 
   
//   for (int i = 0; i < GridView1.Rows.Count; i++)//从第一一行循环至结束,一次更新所有的成绩
//   {       
//    GridViewRow row = GridView1.Rows[i];//定义grideviewrow
//    c.成绩 =Convert.ToDecimal(((TextBox)row.Cells[0].FindControl("TextBox1")).Text);//将TextBox1中输入的字符串转化为Decimal型
//    c.课程号 = GridView1.DataKeys[i].Values[0].ToString();
//    c.学号 = GridView1.DataKeys[i].Values[1].ToString();
//    if (ChafenBOLActions.UpdateScore(c) == 1)
//    { Label1.Text = "更新成功"; }
//    else
//    {
//     break;//更新不成功,跳出
//    }
//          
//   }
   int ct=0;
   if(IsPostBack)
   {
    
    bool b;
    ArrayList ar=new ArrayList();
    for(int i=0;i<DataGrid2.Items.Count;i++)
    { 
     b=((CheckBox)DataGrid2.Items[i].FindControl("CheckBoxSelect")).Checked;
     if (b)
     {
      ct++;
     }
    }
    
   }
   Response.Write(ct);
  }

  private void CheckBoxSelectAll_CheckedChanged(object sender, System.EventArgs e)
  { 
   
//   selected=!selected;

   for(int i=0;i<DataGrid2.Items.Count;i++)
   {     
    ((CheckBox)DataGrid2.Items[i].FindControl("CheckBoxSelect")).Checked= CheckBoxSelectAll.Checked;
   }
  }
 

  
 }
}

 wan
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值