Click here to Skip to main content
15,937,006 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...
Updated 20-Jun-10 7:52am

1 solution

gridview can be binded using a datasource.

gridview1.DataSource = methodToRetrievefromDB(DropDownTableName.SelectedValue);

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

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