View Single Post
Join Date: Dec 2007
Posts: 34
Reputation: vizy is an unknown quantity at this point 
Solved Threads: 6
vizy's Avatar
vizy vizy is offline Offline
Light Poster

Re: Master/Detail DropDownList and DataGrid

 
0
  #6
Dec 3rd, 2008
Try doing this.. it should work

Replace this code :
  1. ddlItems.DataSource = dsCategory;
  2. ddlItems.DataMember = "Categories";
  3. ddlItems.DataTextField = "Description";

With
  1. ddlItems.DataSource = dsCategory;
  2. ddlItems.DataValuefield = "CategoryId";
  3. ddlItems.DataTextField = "CategoryName";

and also puut all your code under Page_Load like this

  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.  
  4. if(!IsPostback)
  5. {
  6. //This code is filling in the Dropdownlist with data from Category table
  7. // your complete Dropdown code here
  8.  
  9. }
  10. }

and in your SelectedIndexChanged function
change this

  1. DataSet dsItems = new DataSet(); daItems.SelectCommand.CommandText = "Select ProductName, UnitPrice, UnitsInStock, ProductImage from dbo.Products where CategoryID = " + [B]ddlItems.SelectedValue[/B];
Last edited by peter_budo; Dec 3rd, 2008 at 7:00 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Njoy koding... >>>
Reply With Quote