how to select with DropDownList.text

前端 未结 8 2370
逝去的感伤
逝去的感伤 2020-12-28 21:56

I am working on an Asp.NET project and I am trying to set the selected value of a dropdown list with a text property. For example i have i.e an item in the dropdown list wit

相关标签:
8条回答
  • 2020-12-28 22:47

    Use this...

    protected void Page_Load(object sender, EventArgs e)
    {
        string t = "test";
        drpFunction.SelectedItem.Text = t;
    }
    

    or

    protected void Page_Load(object sender, EventArgs e)
    {
        string t = "test";
        drpFunction.SelectedItem.Value = t;
    }
    

    this is proper way.......

    0 讨论(0)
  • 2020-12-28 22:50

    Setting the itm.Selected = true; only works if you drp.ClearSelection() first. I prefer the following:

    drpFunction.SelectedValue = drpFunction.Items.FindByText(t).Value;
    
    0 讨论(0)
提交回复
热议问题