.net中怎麼用dropdownlist控制div的顯示
前臺: <tr>
<td>
<div id="Cf" runat="server" class="hide">
重複發生在每<asp:DropDownList ID="ddlSc_Cfrc" runat="server" OnSelectedIndexChanged="ddlSc_Cfrc_SelectedIndexChanged">
<asp:ListItem>天</asp:ListItem>
<asp:ListItem>周</asp:ListItem>
<asp:ListItem>月</asp:ListItem>
</asp:DropDownList>
</div>
</td>
</tr>
<tr >
<td>
<div id="Cfz" runat="server" style="display:none">
<table>
<tr>
<td>
<asp:CheckBoxList ID="Cbl" runat="server" RepeatColumns="7">
<asp:ListItem>周日</asp:ListItem>
<asp:ListItem>周一</asp:ListItem>
<asp:ListItem>周二</asp:ListItem>
<asp:ListItem>周三</asp:ListItem>
<asp:ListItem>周四</asp:ListItem>
<asp:ListItem>周五</asp:ListItem>
<asp:ListItem>周六</asp:ListItem>
</asp:CheckBoxList>
</td>
</tr>
</table></div>
<div id="Cfy" runat="server" style="display:none">
<table>
<tr>
<td>
第<asp:TextBox ID="txttime" runat="server"></asp:TextBox>天
</td>
</tr>
</table>
</div>
後臺: protected void ddlSc_Cfrc_SelectedIndexChanged(object sender, EventArgs e)
{
string str = ddlSc_Cfrc.SelectedIndex.ToString();
if (str == "1")
{
Cfz.Style.Value = "display:''";
}
else
{
Cfz.Style.Value = "display:none";
}
}
[解决办法]
代码应该没问题 是否启用了AutoPostBack="True"
[解决办法]
AutoPostBack属性没有设置为true,如果实现这样的功能建议不要后台处理
<form id="form1" runat="server">
<script type="text/javascript">
function changeSelect(obj) {
alert(obj.value);
if (obj.value == "周") {
document.getElementById("Cfz").style.display = "block";
document.getElementById("Cfy").style.display = "none";
} else if (obj.value == "天") {
document.getElementById("Cfz").style.display = "none";
document.getElementById("Cfy").style.display = "block";
}
}
</script>
<asp:DropDownList ID="ddlSc_Cfrc" runat="server" onchange="changeSelect(this)">
<asp:ListItem>天</asp:ListItem>
<asp:ListItem>周</asp:ListItem>
<asp:ListItem>月</asp:ListItem>
</asp:DropDownList>
<div id="Cfy" style="display:none">yyyyyy</div>
<div id="Cfz" style="display:none">zzzzzzzzz</div>
</form>