Click here to Skip to main content
15,868,158 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I'm currently facing a problem while fetching data from database for modification purposes.
Database consisted of two tables:-
Category (CatId, CatName, CatDescrip)
Brand (CatId, BrandId, BName, BDescrip)

To modify brand table I am required to list CatId, BrandId.
I used a dropdown list for this.

One dropdown contains category, the other contains brand.
When I select category the corresponding brand is filled in the second dropdown.

Upto this point, all is well.

But when I select Brand rather then Category then dropdown selecteditemchanged index so detail corresponding to only for 1st item of 2nd dropdown.

Please help me.
in the page load the line of code is as:

C#
if (!Page.IsPostBack)
        {
           
            DrpModifyBrandCategory();
        }
        DrpModifyBrand();
 public void DrpModifyBrandCategory()
    {
        try
        {
            ConnectionClass classobj = new ConnectionClass();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = classobj.GetCon();
            cmd.CommandText = "select CategoryId,CategoryName from Category";
            SqlDataReader dr = cmd.ExecuteReader();
            drpModifyBrandCategtory.Items.Clear();
            while (dr.Read())
            {
                ListItem l = new ListItem();
                l.Value = dr["CategoryId"].ToString();
                l.Text = dr["CategoryName"].ToString();
                drpModifyBrandCategtory.Items.Add(l);
            }
            dr.Close();
            cmd.Connection.Close();
        }
        catch (Exception ex)
        {
           lblBrandModify.Visible = true;
            lblBrandModify.Text = ex.Message;
        }
    
    }
    public void DrpModifyBrand()
    {
        try
        {
            ConnectionClass classobj = new ConnectionClass();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = classobj.GetCon();
            cmd.CommandText = "select BrandId,BrandName from Brand where CategoryId = " + drpModifyBrandCategtory.SelectedValue;
            SqlDataReader dr = cmd.ExecuteReader();
            drpModifyBrand.Items.Clear();
            while (dr.Read())
            {
                ListItem l = new ListItem();
                l.Value = Convert.ToString(dr["BrandId"]);   //dr["BrandId"];
                l.Text = dr["BrandName"].ToString();
                drpModifyBrand.Items.Add(l);
            }
            dr.Close();
            cmd.Connection.Close();
        }
        catch (Exception ex)
        {
            lblBrandModify.Visible = true;
            lblBrandModify.Text = ex.Message;
        }
Posted
Updated 29-Nov-10 22:59pm
v5
Comments
thatraja 30-Nov-10 1:14am    
Include your drop-downs coding in your question so that we can solve.
Balwant.mnd 30-Nov-10 1:32am    
plz solve this problem as soon as possible
Ashika s 30-Nov-10 1:33am    
plz send the code in detailed
Sunasara Imdadhusen 30-Nov-10 1:53am    
Please provide code for drpModifyBrandCategtory_selectedIndexChanged
Dalek Dave 30-Nov-10 3:46am    
Edited for Grammar, Spelling, Syntax and Readability.

1 solution

Hi,

As per as i understand the problem, we need to bind the Brand dropdown list and then bind the Category

I see there is a error here
if (!Page.IsPostBack)
{
DrpModifyBrandCategory();
}
DrpModifyBrand();

if (!Page.IsPostBack)
{
DrpModifyBrandCategory();
DrpModifyBrand();
}

If you can post the entire code i can figure-out the issue and get you a right answer if this not working.
 
Share this answer
 
Comments
Balwant.mnd 30-Nov-10 5:04am    
this is not working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900