DataGrid中使用CheckBox的CheckedChanged事件

该博客为转载内容,转载自https://www.cnblogs.com/BillChen/archive/2005/09/07/231765.html ,涉及UI相关信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用DataGrid的过程中常会用到CheckBox控件,并使用它的CheckedChanged事件。使用如下:

1、CheckBox控件需要设置AutoPostBack="true"
None.gif<asp:CheckBox id="chbIsActive" runat="server" AutoPostBack="true"></asp:CheckBox>

2、CheckBox控件的事件须在DataGrid的ItemCreated定义才能生效
None.gif        private void grdStructure_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
InBlock.gif                CheckBox chbIsActive 
= e.Item.FindControl("chbIsActive"as CheckBox;
InBlock.gif                chbIsActive.CheckedChanged 
+= new EventHandler(chbIsActive_CheckedChanged);
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }

3、编写事件代码
None.gif        private void chbIsActive_CheckedChanged(object sender, EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            CheckBox chbIsActive 
= (CheckBox)sender;
InBlock.gif
InBlock.gif            Guid structureUID 
= new Guid(chbIsActive.Attributes["StructureUID"]);
InBlock.gif            
bool isActive = chbIsActive.Checked;
InBlock.gif
InBlock.gif            IPMStructureManager manager 
= PMStructureManagerFactory.GetInstance();
InBlock.gif            manager.SetActive(structureUID, isActive);
InBlock.gif
InBlock.gif            
this.Binding();
ExpandedBlockEnd.gif        }

转载于:https://www.cnblogs.com/BillChen/archive/2005/09/07/231765.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值