Saturday, July 10, 2010

How to bulid a simple cascade dropdownlist - Asp.net

<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script runat="server">
        protected void SelectSubCategoies(object sender, EventArgs e)
        {
            string s = this.ddlCategories.SelectedValue;
            this.ddlSubcategories.Items.Clear();
            if (s.Equals("-1"))
                this.ddlSubcategories.Enabled = false;
            else
            {
                this.ddlSubcategories.Enabled = true;
                for (int i = 0; i < 10; i++)
                    this.ddlSubcategories.Items.Add(new ListItem(s + " Sub Cateogry"));
            }
        }
    </script>
</head>
<body>
    
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel runat="server" ID="upnlCascadeDropdown">
             <ContentTemplate>
                  <asp:DropDownList runat="server" ID="ddlCategories" 
                            AutoPostBack="true" OnSelectedIndexChanged="SelectSubCategoies">
                       <asp:ListItem Value="-1">Select</asp:ListItem>
                       <asp:ListItem Value="A">Category A</asp:ListItem>
                       <asp:ListItem Value="B">Category B</asp:ListItem>
                       <asp:ListItem Value="C">Category C</asp:ListItem>
                       <asp:ListItem Value="D">Category D</asp:ListItem>
                  </asp:DropDownList>
                  <asp:DropDownList runat="server" ID="ddlSubcategories" 
                                                Enabled="false"></asp:DropDownList>
             </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...