I am trying to populate another combobox based on the text selected in the first combo box...however , the event protected void ddlcity_SelectedIndexChanged(object sender, EventArgs e) is not firing ?
here is my code snippet :

protected void ddlcity_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlDataReader dr1 = null;
        SqlCommand command = new SqlCommand("select category.category from category,city_master,wines_available where wines_available.city_id=city_master.city_id and wines_available.category_id=category.category_id and city_master.city_name= '" + ddlcity.SelectedItem+ "'", conn);
        conn.Open();
        dr1 = command.ExecuteReader(CommandBehavior.CloseConnection);
        ddlcategory.DataSource = dr1;
        ddlcategory.DataTextField = "Category";
        ddlcategory.DataValueField = "Category";
        ddlcategory.DataBind();
        dr1.Close();
    }

However , when i change the text in the first combobox second combo box(ddlcategory) does not get populated..plz help me out.


cya
Rohan

Recommended Answers

All 3 Replies

please set "autopostback" property of comboboxes to true....

Okie...it worked!!!
cya
Rohan

please set "autopostback" property of comboboxes to true....

hi.. i have written a sample code with static text.. .try it and check ur db once....

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedItem.Value == "one")
        {
            DropDownList2.Items.Clear();
            DropDownList2.Items.Add("hello1");
            DropDownList2.Items.Add("hii1");

        }

        if (DropDownList1.SelectedItem.Value == "two")
        {
            DropDownList2.Items.Clear();
            DropDownList2.Items.Add("hello2");
            DropDownList2.Items.Add("hii2");

        }
        if (DropDownList1.SelectedItem.Value == "three")
        {
            DropDownList2.Items.Clear();
            DropDownList2.Items.Add("hello3");
            DropDownList2.Items.Add("hii3");

        }
        if (DropDownList1.SelectedItem.Value == "four")
        {
            DropDownList2.Items.Clear();
            DropDownList2.Items.Add("hello4");
            DropDownList2.Items.Add("hii4");

        }
    }

source code is

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Newfile.aspx.cs" Inherits="Newfile" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem>one</asp:ListItem>
            <asp:ListItem>two</asp:ListItem>
            <asp:ListItem>three</asp:ListItem>
            <asp:ListItem>four</asp:ListItem>
        </asp:DropDownList>
        <asp:DropDownList ID="DropDownList2" runat="server">
        </asp:DropDownList></div>
    </form>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.