Click here to Skip to main content
14,448,694 members
Rate this:
Please Sign up or sign in to vote.
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!!
Updated 9-Nov-11 0:46am
Rate this:
Please Sign up or sign in to vote.

Solution 1

Your question is some what confusing rephrase it

as far as i understood
This may give you some idea[^]
Rate this:
Please Sign up or sign in to vote.

Solution 2

for adding a dropdown in gridview refer:[^]

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:
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];
Rate this:
Please Sign up or sign in to vote.

Solution 3

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
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
Rate this:
Please Sign up or sign in to vote.

Solution 4

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..

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100