前台:
<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;
为什么只能获取到第一个的选中的值,后面选中的获取不到呢。请教高手帮忙指点。非常感谢。
看一下你的页面源代码呢?是不是你的数据绑定出了点意外?
string address1 = this.sheng.SelectedItem.Text;
你直接用dropdownlist,搞搞算了
你是用的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;
}