C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-17-2009, 02:33 AM   #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 04:54 AM. Reason: i is defined before
Aga^^ is offline   Reply With Quote
Old 07-17-2009, 08:08 AM   #2
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,125
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.
Magos is offline   Reply With Quote
Old 07-17-2009, 08:30 AM   #3
Registered User
 
Aga^^'s Avatar
 
Join Date: Aug 2008
Posts: 71
yeah that's it thanks a lot Magos
Aga^^ is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Laptop Problem Boomba Tech Board 1 03-07-2006 06:24 PM
Problem with Vectors And Pointers Shamino Game Programming 3 01-21-2006 07:23 PM
design problem hannibar C Programming 6 11-17-2005 06:22 PM
Sorting problem.. well actually more of a string problem fatdunky C Programming 5 11-07-2005 11:34 PM
Didn't quite know where to post this.......compiler problem... incognito C++ Programming 5 02-08-2003 07:42 PM


All times are GMT -6. The time now is 04:52 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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