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:
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"]);
l.Text = dr["BrandName"].ToString();
drpModifyBrand.Items.Add(l);
}
dr.Close();
cmd.Connection.Close();
}
catch (Exception ex)
{
lblBrandModify.Visible = true;
lblBrandModify.Text = ex.Message;
}