我有一个填充的DropDownList。如何找到Text值为“x”的索引?
答案 0 :(得分:42)
如果你想在服务器端获得价值,你可以遵循这个。
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.
答案 1 :(得分:0)
试试。
ddlsample2.SelectedIndex = ddlsample.FindStringExact(ddlsample.Text);