关于DropDownList的怪事
我一个页面,只有一个dropdownlist和一个label
label即时显示dropdownlist的被选项内容;
但是碰到一个怪问题,就是我只要选取ddl的最后两个选项,也就是Hyperion或者4AD,那么label的显示总是显示Archiv那个选项,也就是倒数第三个,我调试了之后发现selectedindexchanged事件触发后,传递的index值就是5,也就是说只要选第6或者第7个选项,传递的index值总是5,但是选择5之前的选项都没关系。
这真是出鬼了啊!!求高手帮我看看到底问题出在哪儿!Thx....
aspx就没什么看的了,就一个ddl一个label,cs文件如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Chapter4_DropDownList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[,] Label ={
{ "ECM ", "Germany "},
{ "EMI ", "France "},
{ "Vigin ", "France "},
{ "DG ", "German "},
{ "CMI ", "Sweden "},
{ "Archiv ", "UK "},
{ "Hyperion ", "UK "},
{ "4AD ", "UK "}
};
for (int i = 0; i < Label.GetLength(0); i++)
{
ddlLabel.Items.Add(new ListItem(Label[i,0],Label[i,1]));
}
lblRecord.Text = "Label Name: " + ddlLabel.SelectedItem.Text + " Country: " + ddlLabel.SelectedValue;
}
}
protected void ddlLabel_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlLabel.SelectedIndex != -1)
{
lblRecord.Text = "Label Name: " + ddlLabel.SelectedItem.Text + " Country: " + ddlLabel.SelectedValue;
}
}
}
[解决办法]
你把{ "Archiv ", "UK "},{ "Hyperion ", "UK "},{ "4AD ", "UK "}改成{ "Archiv ", "UK1 "},{ "Hyperion ", "UK2 "},{ "4AD ", "UK3 "}试下
[解决办法]
Select value 重复了
{ "Archiv ", "UK1 "},
{ "Hyperion ", "UK2 "},
{ "4AD ", "UK3 "}
{ "EMI ", "France1 "},
{ "Vigin ", "France2 "},
[解决办法]
dropdownlist.Selectedvalue 重复,都是 "UK "
{ "Archiv ", "UK "},{ "Hyperion ", "UK "},{ "4AD ", "UK "}
[解决办法]
value重复.
[解决办法]
Selectedvalue 重复
[解决办法]
把{ "Archiv ", "UK "},{ "Hyperion ", "UK "},{ "4AD ", "UK "}改成{ "Archiv ", "UK1 "},{ "Hyperion ", "UK2 "},{ "4AD ", "UK3 "}
或者把ddlLabel.Items.Add(new ListItem(Label[i,0],Label[i,1])); 改为
ddlLabel.Items.Add(new ListItem(Label[i,1],Label[i,0]));