如何获取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"));//1ListItem listItem = this.DropDownList1.Items.FindByText("1");//1为text
int index = this.DropDownList1.Items.IndexOf(listItem);//你像要的