Finding DropDownList index by text
I have a populated DropDownList. 开发者_开发问答How do I find the index whose Text value is "x"?
If you want to get value on server side you can follow this.
ddlsample.SelectedIndex = ddlsample.Items.IndexOf(ddlsample.Items.FindByValue("x")); // If you want to find text by value field.
ddlsample.SelectedIndex = ddlsample.Items.IndexOf(ddlsample.Items.FindByText("x"));// If you want to find text by TextField.
try tis.
ddlsample2.SelectedIndex = ddlsample.FindStringExact(ddlsample.Text);
精彩评论