![]() |
| | #1 |
| Registered User Join Date: Aug 2008
Posts: 71
| 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();
}
i am waiting your answers.. Last edited by Aga^^; 07-17-2009 at 04:54 AM. Reason: i is defined before |
| Aga^^ is offline | |
| | #2 |
| Confused 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 | |
| | #3 |
| Registered User Join Date: Aug 2008
Posts: 71
| yeah that's it thanks a lot Magos |
| Aga^^ is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |