Problem in DropDownList's SelectedIndexChanged Event

This is a discussion on Problem in DropDownList's SelectedIndexChanged Event within the C# Programming forums, part of the General Programming Boards category; hi guys, i am working on a library automation system in ASP.NET with C#. I think this part of the ...

  1. #1
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71

    Question Problem in DropDownList's SelectedIndexChanged Event

    hi guys,
    i am working on a library automation system in ASP.NET with C#. I think this part of the forum is suitable.
    When i come to my problem
    in admin panel i designed a "Book Addition" page . In this part admin choose category and subcategory to add the book. The category names will be listed on Page_Load, admin chooses a category name and the subcategories which is related to the choosen category will listed on ddlSubcategory.

    here is my code
    Code:
    int i;
    
    protected void ddlCat_SelectedIndexChanged(object sender, EventArgs e)
        {
            ddlScat.Items.Clear();
    
            SqlConnection connect = dbConnection.GetConnection();
            SqlCommand cmd2 = new SqlCommand("select c_id from categories where c_name=@catname", connect);
            cmd2.Parameters.AddWithValue("@catname", ddlCat.SelectedValue.ToString());
            //cmd2.Parameters.AddWithValue("@catname", ddlCategory.SelectedItem.Value);
            connect.Open();
            SqlDataReader rdr2 = cmd2.ExecuteReader();
    
            while (rdr2.Read())
            {
                i = Int32.Parse(rdr2.GetValue(0).ToString());
            }
            connect.Close();
            connect.Open();
            SqlCommand command2 = new SqlCommand("select s_name,s_id from subcategories where c_id=@i", connect);
            command2.Parameters.AddWithValue("@i", i);
    
            SqlDataAdapter da = new SqlDataAdapter(command2);
            DataTable dt = new DataTable();
    
            da.Fill(dt);
    
            ddlScat.DataSource = dt;
            ddlScat.DataTextField = "s_name";
            ddlScat.DataValueField = "s_id";
            ddlScat.DataBind();
    
            connect.Close();
    
        }
    there is no warning or error. And Page_load part is working correctly but when i clicked ddlCat ( drop down list of Categories ) the ddlScat ' s( drop down list of subcategories ) items do not change.

    i am waiting your answers..
    Last edited by Aga^^; 07-17-2009 at 05:54 AM. Reason: i is defined before

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Have you set the "AutoPostback" property on the dropdownlist to True?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71
    yeah that's it thanks a lot Magos

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  2. Problem with Vectors And Pointers
    By Shamino in forum Game Programming
    Replies: 3
    Last Post: 01-21-2006, 07:23 PM
  3. design problem
    By hannibar in forum C Programming
    Replies: 6
    Last Post: 11-17-2005, 06:22 PM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21