当用户点击ASP页面中的复选框时,我只想看一个Html表(id ='xx')。一旦用户在复选框上取消选中,表格就会再次隐藏。
<table>
<tr>
<td colspan='2'>
<table id='xx'>
<tr>
<td colspan='2'>
Student Information :
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Select Student name :"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Width="200px">
</asp:DropDownList>
</td>
</tr>
...
我试过这段代码:
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked == true)
{
// need a way to hide the Table id='xx'
}
else {
DropDownList1.Visible = true; // This is also not working
}
}
请帮帮我。
答案 0 :(得分:3)
在回发时使用 AutoPostBack =“true”进行CheckBox控制。
答案 1 :(得分:1)
试试这个......
<table>
<tr>
<td colspan='2'>
<asp:CheckBox runat="server" ID="CheckBox1" Text="check" Checked="true" AutoPostBack="true"
OnCheckedChanged="CheckBox1_CheckedChanged" />
<table id='xx' runat="server">
<tr>
<td colspan='2'>
Student Information :
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Select Student name :"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Width="200px">
</asp:DropDownList>
</td>
</tr>
</table>
</td>
</tr>
</table>
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
this.xx.Visible = CheckBox1.Checked;
}
答案 2 :(得分:1)
这里有两个选择......
- 使用runat =&#34; server&#34;
制作表服务器控件- 在Check / UnCheck CheckBox控件上,将display属性设置为True / False。
醇>
<table id='xx' runat = "server">
现在您可以访问下面的表格控件
xx.Visible = true/false;
<asp:CheckBox onclick="return SelectChk(this);" ID="chk" ></asp:CheckBox>
JavaScript功能
<script language="javascript" type="text/javascript">
function SelectChk(CtlId) {
var IsChecked = document.getElementById(CtlId.id).checked;
if (IsChecked) {
document.getElementById(<%=xx.ClientID%>).style.display = 'block';
}
else{
document.getElementById(<%=xx.ClientID%>).style.display = 'none';
}
}
</script>