首页 新闻 会员 周边 捐助

select 控件中获取option 的文本值

0
[待解决问题]

前台:

    <select id="sheng" runat="server" onchange="changsheng(this.value)">
                        <option selected="selected">-请选择省-</option>
                    </select>
                    
                    <select id="city" runat="server" onchange="changshi(this.value)">
                        <option selected="selected">-请选择市-</option>
                    </select>

                    <select id="qu" runat="server">
                        <option selected="selected">-请选择区-</option>
                    </select>

 

后台CS

string address1 = this.sheng.Items[this.sheng.SelectedIndex].Text;
        string address2 = this.city.Items[this.city.SelectedIndex].Text;
        string address3 = this.qu.Items[this.qu.SelectedIndex].Text;

 

为什么只能获取到第一个的选中的值,后面选中的获取不到呢。请教高手帮忙指点。非常感谢。

Snail1688的主页 Snail1688 | 菜鸟二级 | 园豆:202
提问于:2012-10-07 11:27
< >
分享
所有回答(4)
0

看一下你的页面源代码呢?是不是你的数据绑定出了点意外?

田林九村 | 园豆:2367 (老鸟四级) | 2012-10-07 18:26
0

string address1 = this.sheng.SelectedItem.Text;

gunsmoke | 园豆:3592 (老鸟四级) | 2012-10-08 06:58
0

你直接用dropdownlist,搞搞算了

chenping2008 | 园豆:9836 (大侠五级) | 2012-10-08 10:05
0

你是用的vs哪个版本啊?我在vs20中运行了一下,可以啊,代码如下:

前台:

<head runat="server">
<title></title>
<script type="text/javascript">
function changsheng(str)
{
document.getElementById("sheng").value=str ;
}
function changshi(str)
{
document.getElementById("city").value = str;
}

</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<select id="sheng" runat="server" onchange="changsheng(this.value)">
<option selected="selected">-请选择省-</option>
<option>-请选择省11-</option>
</select>
<select id="city" runat="server" onchange="changshi(this.value)">
<option selected="selected">-请选择市-</option>
<option>-请选择市11-</option>
</select>
<select id="qu" runat="server">
<option selected="selected">-请选择区-</option>
<option>-请选择区11-</option>
</select>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>

后台:

protected void Button1_Click(object sender, EventArgs e)
{
string address1 = this.sheng.Items[this.sheng.SelectedIndex].Text;
string address2 = this.city.Items[this.city.SelectedIndex].Text;
string address3 = this.qu.Items[this.qu.SelectedIndex].Text;
}

求知的我 | 园豆:203 (菜鸟二级) | 2012-10-11 10:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册