Thursday, January 9, 2014

DropDownList FindByText

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:DropDownList ID="ddl1" runat="server">
    <asp:ListItem>One</asp:ListItem>
    <asp:ListItem>Two</asp:ListItem>
    <asp:ListItem>Three</asp:ListItem>
    </asp:DropDownList>
    </div>
    </form>
</body>
</html>


 



protected void Page_Load(object sender, EventArgs e)
    {
        ListItem item = ddl1.Items.FindByText("Three");
        if (item != null)
        {
            ddl1.ClearSelection();
            item.Selected = true;
        }
    }

0 comments:

Post a Comment