读书人

.net中怎用dropdownlist统制div的

发布时间: 2013-07-01 12:33:04 作者: rapoo

.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";
}
}


:怎ddlSc_Cfrc“周”後使"Cfz"示,“天”後使"Cfy"示,希望各位多多助,!(SelectedIndexChanged中的方法用) dropdownlist ?div??? .NET


[解决办法]
代码应该没问题 是否启用了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>

读书人网 >C#

热点推荐