-4

I want ASP .NET code for as example-

As I have four drop down box, when i will select the value in first box then in second box filtered value according to first box should be without any page refresh please help me.

Example-

I am giving you the example of country, state, city. when i will select the country then in second box all states should be updated according to country as when i will select the state then all city name should be updated in third box.

This process should be without refreshing the page.

user3745023
  • 31
  • 1
  • 4

1 Answers1

0

If you are using webforms,you can use an UpdatePanel in your webforms and giving drop downlist in the update panels.. Please find the sample code

List<Districts> list = new List<Districts>();
Districts item = new Districts();

protected void Page_Load(object sender, EventArgs e)
{
     if (drd1.SelectedItem.Value == "Kerala")
     {
        item.sname = "Ekm";
        item.id = 1;
        list.Add(item);
        Districts item1 = new Districts();
        item1.sname = "thr";
        item1.id = 2;
        list.Add(item1);
     }
     else
     {
        item.sname = "Coimbatore";
        item.id = 1;
        list.Add(item);
        Districts item1 = new Districts();
        item1.sname = "Chennai";
        item1.id = 2;
        list.Add(item1);
     }
  }

public class Districts
{
    public string sname { get; set; }
    public int id { get; set; }
}
protected void drd1_SelectedIndexChanged(object sender, EventArgs e)
{
    drd2.DataSource = list;
    drd2.DataTextField = "sname";
    drd2.DataValueField = "id";
    drd2.DataBind();
}

and your page looks like this

   <asp:ScriptManager ID="scr" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="upd" runat="server" >
        <ContentTemplate>
            <asp:DropDownList ID="drd1" runat="server" AutoPostBack="true"  OnSelectedIndexChanged="drd1_SelectedIndexChanged">
                <asp:ListItem Text="Kerala" Value="Kerala">
                </asp:ListItem>
                <asp:ListItem Text="TN" Value="TN"></asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList ID="drd2" runat="server" Width="100"></asp:DropDownList>
        </ContentTemplate>
    </asp:UpdatePanel>
Denny
  • 1
  • 1
  • 3