DataGrid中使用CheckBox的CheckedChanged事件
使用DataGrid的过程中常会用到CheckBox控件,并使用它的CheckedChanged事件。使用如下:
1、CheckBox控件需要设置AutoPostBack="true"
<asp:CheckBox id="chbIsActive" runat="server" AutoPostBack="true"></asp:CheckBox>
2、CheckBox控件的事件须在DataGrid的ItemCreated定义才能生效
private void grdStructure_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
CheckBox chbIsActive = e.Item.FindControl("chbIsActive") as CheckBox;
chbIsActive.CheckedChanged += new EventHandler(chbIsActive_CheckedChanged);
}
}
3、编写事件代码
private void chbIsActive_CheckedChanged(object sender, EventArgs e)
{
CheckBox chbIsActive = (CheckBox)sender;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Guid structureUID = new Guid(chbIsActive.Attributes["StructureUID"]);
bool isActive = chbIsActive.Checked;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
IPMStructureManager manager = PMStructureManagerFactory.GetInstance();
manager.SetActive(structureUID, isActive);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
this.Binding();
}
1、CheckBox控件需要设置AutoPostBack="true"
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2、CheckBox控件的事件须在DataGrid的ItemCreated定义才能生效
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
3、编写事件代码
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)