Click here to Skip to main content
15,744,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Confused how to create dynamic Grid View such that in combo box i select the item it'll show its records in Grid View

simple is that there is a window have two things one is combo box contains the name of tables e.g userTb and CustomerTb
and other one is data grid view ... now if i select userTB it'll show userTb in grid view and when i select CustomerTb it'll show customer records in grid view...
Posted
Updated 20-Jun-10 7:52am
v3

1 solution

gridview can be binded using a datasource.

C#
gridview1.DataSource = methodToRetrievefromDB(DropDownTableName.SelectedValue);
gridview1.DataBind();

In methodToRetrievefromDB(string TableName) you'll have to apply checks for Table to retrieve records from and execute the procedure for the selected table.

On change of value of drop down you must retrieve records each time. You can store both tables in a temporary space and use that if you want to avoid hitting DB again and again but it depends on the number of records and tables.
 
Share this answer
 
v3

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