DropDownList 默认值的问题~~请高手帮忙看看
ASPX文件:
<asp:DropDownList ID= "CityList " runat= "server " AutoPostBack= "True " OnSelectedIndexChanged= "ddl_area_SelectedIndexChanged ">
<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: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: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: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:ListItem> 内蒙 </asp:ListItem>
<asp:ListItem> 宁夏 </asp:ListItem>
<asp:ListItem> 山西 </asp:ListItem>
<asp:ListItem> 青海 </asp:ListItem>
<asp:ListItem> 黑龙江 </asp:ListItem>
</asp:DropDownList>
CS文件:
protected void Page_Load(object sender, EventArgs e)
{
String CityId = Request.QueryString[ "CityId "];
Response.Write(CityId);
if (CityId != null)
{
CityList.Items[Convert.ToInt16(CityId)].Selected = true;
}
}
protected void ddl_area_SelectedIndexChanged(object sender, EventArgs e)
{
if (CityList.SelectedIndex != 0)
{
Response.Redirect( "SelectCity.aspx?act=City&CityId= " + CityList.SelectedIndex);
}
}
问题如下:
1.默认值只能从最后向前选择才有效,如果第一次就选择了 "全国 ",那再选择后面的怎么选还是 "全国 "
2.如果选择了 "==请选择地区== "
就会出现错误
<不能在 DropDownList 中选择多个项。>
我不是在程序做过判断CityList.SelectedIndex != 0才执行吗
[解决办法]
不是吧.楼主想要什么效果呢?
如果DropDownList加上Value值不就好办些.
或者楼主加多一个条件试试吧.
if (CityList.SelectedIndex != 0 || CityList.Text != "==请选择地区== ")
{
Response.Redirect( "SelectCity.aspx?act=City&CityId= " + CityList.SelectedIndex);
}