Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to add a drop-down in a gridview. In my application i want to fill values of second dropdown from the value of first dropdown which is entered by the user. ie. In first dropdown i want to fill the product name.When i select product name then i want to fill the second dropdown with price related to that product name which i selected from the first dropdown.
How can i do it?

if you can proved me with the code in C# it would be grateful!!
Posted
Updated 8-Nov-11 23:46pm
v4

Your question is some what confusing rephrase it

as far as i understood
This may give you some idea

http://forums.asp.net/t/1431726.aspx/1?populate+one+dropdownlist+based+upon+action+of+another+dropdownlist[^]
 
Share this answer
 
v2
for adding a dropdown in gridview refer:
http://highoncoding.com/Articles/169_DropDownList_Inside_GridView__Method_1_.aspx[^]

and for having the the items in the secodd dropdown depending on selection of first dropdown u should use SelectedIndexChanged event of first dropdown, as:
C#
protected void ddlProduct_SelectedIndexChanged(object sender, EventArgs e)
   {       
       int product_id= Convert.ToInt32(ddlProduct.SelectedValue);
       ds = belobj.GetDataSet("GetPrice", "PRODUCT_ID=" + product_id);//get the values for price from database
       ddlPrice.DataSource = ds.Tables[0];
      
       ddlPrice.DataBind();
   }
 
Share this answer
 
v2
You really should be doing this in an Object Oriented manner. You should have a class called Product. Then when your user opens the billing form, you should populate the Product ComboBox with a List of the Products. When the user selects a Product from the Combo, the retail price and everything is automatically included as part of the class, and so you could populate a Textbox with the retail price and maybe another with the available quantity, then the user can just select a quantity with a numeric up down control and click an addtobill button which then includes the selected item and quantity in the DataGridView. Then you couls have a saveandprint button which saves the order to the database and prints a receipt/invoice.

Hope this helps
 
Share this answer
 
Comments
Xaiver101 9-Nov-11 5:44am    
Thanks mate! that was a really good point.. if you dont mind can you give me a link or a sample code for how to populate the combo box..
im still a beginner.. :)
Wayne Gaylard 9-Nov-11 5:53am    
Just create a Product class say with properties ID, Description, Price and StockLevel. Then create another class that derives from List<product> and populate it from the database. Then you can set the COmboBox's DataSource property to that class, and set DisplayMember to Description, and ValueMember to ID. Then the combo will be filled with your products, and when your user selects one, you can access it through the SelectedItem property. Hope this helps
You need to add selectedindexchanged event of first dropdown and from there you can dynamically change the second dropdown content..
hope it'll help you..
 
Share this answer
 

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