hello. i have the following db structure:
table tools
id, type_id, name
table tooltypes
id, name
i
need to have a datagrid, viewing the tools table, with a
combobox instead of type_id (filled with names of tooltypes, selected value corresponding to type_id). i
know how to do it manually, but i want to find the right way, using
databinding, relations (is it possible?). i've read some tutorials, googled a lot, still i'm confused about this. any help appreciated. thank you.
Loading
Juras NorkusPosted Jan 7, 2009, 7:40 AM
Komal PatelPosted Jan 7, 2009, 7:24 AM
As per your requirement you can go for template field containing combo box.
heare are the steps to do it:
1. create a template field on your grid
2. Add combo box to template feild.
3. now on page load get both tables data in dataset and assign it to session variables to maintain their values during postback.
4. now assign the main dataset to gridview as datasource for which u might have some bound fields on grid
5. and for combo box trap rowdatabound event of grid for each row
6. in row databound event search for your combobobx and assign it's datatext as well as datavalue field from the other dataset
Hope this might help you...
Juras NorkusPosted Jan 6, 2009, 7:43 AM
Rajendra DeopuraPosted Jan 6, 2009, 6:17 AM
Use the following syntax to create a datarelation object.
ds.Relations.Add("relation name",ds.Tables("table1").Columns.("id"), ds.Tables('table2").Columns("id")
Here , ds is the Dataset object.
The first parameter in Add method is name of the relation, second parameter is the column name of parent table,third parameter is column name of child table.
Now you can filter the records via GetChildRows( ) method.
Thanks
Pankaj GuptaPosted Jan 6, 2009, 6:07 AM
First of all fill both the tables in a DATASET and then add the realtion between both tables on the common column "ID".
When you add the relation, you have to also specify the name of the relation. With the use of that relation name and the selected ID, you can get the records from the details tables. This will return you the DATA ROWS collection, bind that data rows directly to the gridview. If you require any futher help, please write.