| « | December 2025 | » | | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | |
|
| 公告 |
Back Today!
Hold on~
Come on~ |
| 统计 |
blog名称:执著 日志总数:39 评论数量:43 留言数量:0 访问次数:247610 建立时间:2005年3月4日 | |
[.net]datagrid里面checkbox的用法 |
| private void Button1_Click(object sender, System.EventArgs e) { CheckBox c1;// = new CheckBox(); for(int i =0;i<dg1.Items.Count;i++) { c1 =(CheckBox)dg1.Items[i].FindControl("CheckBox1"); if(c1.Checked && c1 !=null) { Label1.Text = Label1.Text +dg1.Items[i].Cells[1].Text; Label2.Text = Label2.Text +dg1.Items[i].Cells[2].Text; } }
}
private void dg1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if ( e.Item.Cells[0].Controls.Count > 0 ) { System.Web.UI.WebControls.CheckBox chk; chk = (CheckBox) e.Item.FindControl("CheckBox1"); chk.CheckedChanged += new System.EventHandler(this.chkChanged); } } private void chkChanged(object sender, System.EventArgs e) { for(int m = 0;m<dg1.Items.Count;m++) if (sender.Equals((CheckBox)dg1.Items[m].FindControl("CheckBox1"))) { CheckBox c2; c2 =(CheckBox)dg1.Items[m].FindControl("CheckBox1"); if (c2.Checked) dg1.Items[m].BackColor = Color.SkyBlue; else dg1.Items[m].BackColor = Color.White; } }
button1是指选择多个后要执行的动作
后面两个是每选择一个checkbox该行的背景会变色 | |
|
|
|
|
|