Click here to Skip to main content
Rate this: bad
good
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!!
Posted 8-Nov-11 23:33pm
Edited 9-Nov-11 0:46am
v4
Rate this: bad
good
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
 
http://forums.asp.net/t/1431726.aspx/1?populate+one+dropdownlist+based+upon+action+of+another+dropdownlist[^]
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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:
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();
   }
  Permalink  
v2
Rate this: bad
good
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
  Permalink  
Comments
Xaiver101 at 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 at 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: bad
good
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..
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 274
1 Shweta N Mishra 216
2 PIEBALDconsult 210
3 Sergey Alexandrovich Kryukov 185
4 BillWoodruff 174
0 OriginalGriff 7,620
1 Sergey Alexandrovich Kryukov 6,937
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,495


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 9 Nov 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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