我正在开发一个Asp.NET项目,我正在尝试使用text属性设置下拉列表的选定值.例如,我有一个带有文本的下拉列表中的项目test.我可以selecteditem通过编程方式将其设置为Text?我正在使用以下代码,但无法正常工作.
protected void Page_Load(object sender, EventArgs e)
{
    string t = "test";
    drpFunction.Text = t; 
}
但是没有用.有什么建议 ?
ion*_*den 28
 string t = "test";
 drpFunction.ClearSelection();
 drpFunction.Items.FindByText(t).Selected = true;
小智 6
设置itm.Selected = true; 仅在你首先使用drp.ClearSelection()时才有效.我更喜欢以下内容:
drpFunction.SelectedValue = drpFunction.Items.FindByText(t).Value;