how to select with DropDownList.text

前端 未结 8 2379
逝去的感伤
逝去的感伤 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条回答
  •  旧时难觅i
    2020-12-28 22:38

    This Link might help you

    public static void SelectText(this DropDownList bob, string text)
    {
        try
        {
            if (bob.SelectedIndex >= 0)
                bob.Items[bob.SelectedIndex].Selected = false;
            bob.Items.FindByText(text).Selected = true;
        }
        catch
        {
            throw new GenericDropDownListException("value", text);
        }
    }
    

提交回复
热议问题