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

前端 未结 4 1469
太阳男子
太阳男子 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:02

    If you have to select dropdown selected item text for multiple dropdown cases then use this way.

    // Call Method
    SelectDropdownItemByText(ddlDropdown.Items.FindByText("test"));
    
    // Define method
    public void SelectDropdownItemByText(ListItem item)
    {
        if (item != null)
        {
            item.Selected = true;
        }
    }
    

提交回复
热议问题