读书人

GridView中两个CheckBox(VB.Net+Asp.n

发布时间: 2012-01-13 22:43:29 作者: rapoo

GridView中两个CheckBox(VB.Net+Asp.net)
Gridview中有两个(两列)checkbox,一个是Inactive,另一个是Allow Login。
当选中 Inactive时,Allow Login不被选中,反之,当选中Allow Login 时,Inactive不被选。(类似于单选框)。
请问如何实现?
<asp:TemplateField HeaderText= "Inactive " SortExpression= "User_Inactive ">
<EditItemTemplate>
<asp:CheckBox ID= "CheckBox1 " runat= "server " Checked= ' <%# Bind( "User_Inactive ") %> ' Height= "12px " Width= "50px " />
</EditItemTemplate>
<ItemStyle Width= "10% " />
<HeaderStyle Width= "10% " />
<ItemTemplate>
<asp:CheckBox ID= "CheckBox1 " runat= "server " Checked= ' <%# Bind( "User_Inactive ") %> '
Enabled= "false " />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText= "Allow Login " SortExpression= "User_AllowLogin ">
<EditItemTemplate>
<asp:CheckBox ID= "CheckBox2 " runat= "server " Checked= ' <%# Bind( "User_AllowLogin ") %> ' />


</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID= "CheckBox2 " runat= "server " Checked= ' <%# Bind( "User_AllowLogin ") %> '
Enabled= "false " />
</ItemTemplate>
</asp:TemplateField>

[解决办法]
onbounddata事件中:

CheckBox CheckBox1 = ...FindControl( "CheckBox1 ") as CheckBox
CheckBox CheckBox2 = ...FindControl( "CheckBox2 ") as CheckBox
if(CheckBox1 != null && CheckBox2 != null ) {
CheckBox1.Attributes[ "onclick "] = string.Format( "document.getElementById(\ "{0}\ ").checked = this.checked ? false : true; ",CheckBox2.ClientID);
CheckBox1\2.Attributes[ "onclick "] = string.Format( "document.getElementById(\ "{0}\ ").checked = this.checked ? false : true; ",CheckBox1.ClientID);
}

读书人网 >asp.net

热点推荐