日期:2014-05-17  浏览次数:20711 次

如何获取DropDownList中某个item对应的index?
如何获取DropDownList中某个item对应的index呢?
例如item有'a','b','c',
获取'b'对应的index为1,好像没找到对应的方法?

------解决方案--------------------
绑定数据源的时候
                this.DropDownList1.DataTextField = "item";//显示的值
                this.DropDownList1.DataValueField = "index";//获取dropdownlist中的值
                DropDownList1.DataSource = 你的数据源;
                this.DropDownList1.DataBind();
this.DropDownList1.SelectedValue就是了
------解决方案--------------------
那就是SelectedIndex
------解决方案--------------------
试试
int index = this.DropDownList1.Items.IndexOf(this.DropDownList1.Items.FindByValue("b"));//1

------解决方案--------------------
引用:
试试
int index = this.DropDownList1.Items.IndexOf(this.DropDownList1.Items.FindByValue("b"));//1

正解

DropDownList2.Items.FindByText("b").Selected=true;
        int index = DropDownList2.SelectedIndex;
或将value值直接为索引
DropDownList2.Items.FindByText("b").Value
------解决方案--------------------
ListItem listItem = this.DropDownList1.Items.FindByText("1");//1为text
                int index = this.DropDownList1.Items.IndexOf(listItem);//你像要的