按文本查找DropDownList索引

spu*_*pud 16 asp.net

我有一个填充的DropDownList.如何找到Text值为"x"的索引?

ash*_*lia 43

如果你想在服务器端获得价值,你可以遵循这个.

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.
Run Code Online (Sandbox Code Playgroud)