How can you set the selected item in an ASP.NET dropdown via the display text?

前端 未结 4 1483
太阳男子
太阳男子 2020-12-09 16:54

I have an ASP.NET dropdown that I\'ve filled via databinding. I have the text that matches the display text for the listitem I want to be selected. I obviously can\'t use Se

4条回答
  •  忘掉有多难
    2020-12-09 17:17

    Its working fine ..

    drplistcountry.SelectedIndex = 
    drplistcountry.Items.IndexOf(drplistcountry.Items.FindByText("--Select--"));
    

    Or

    drplistcountry.ClearSelection();
    drplistcountry.SelectedIndex = 
    drplistcountry.Items.IndexOf(drplistcountry.Items.FindByText("--Select--"));
    

提交回复
热议问题