Binding with a DataRelation

D

David D. McCrory

I have a typed dataset that has 2 tables that are related using a
DataRelation. I am displaying the data in 2 separate grids. I want to be
able to select a record in the parent grid and only display the related
child records in the child grid. I have read several posts that discuss
binding to a data relation, but I do not understand how this is supposed to
work. I have tried setting the DataMember property to the DataRelation, but
only the tables are available in the dropdown list. Can someone show me an
example (in C#) of how this can be accomplished?

Thanks in advance......
 
G

Guest

Hi
This might help you.But this is in VB.NET..I think you can easily translate it into a c# code.Now if you still want it in C# then let me know
What you can possible do is that first create a datarelation between the tables in the dataset a
dataset.Relations.Add("Relation Name",dataset.Tables(ParentTableName).Columns(columnName),
dataset.Tables(ChildTableName).Columns(columnName)

Now after creating the datarelation bind the parent table to the grid where yu want it to be displayed.Say for example if it is a dropdownlist then you can bind it as
ddlName.DataSource = parentTabl
ddlName.DataTextField = columnNam
ddlName.DataValueField = columnNam
ddlName.DataBind(

Now upon selection of one value from the grid, get the corresponding row in the parent table
Now you can get all the child rows as ParentTable.GetChildRows(RelationName)
Now using this create a datatable and bind it to the child grid
Hope that this will help you

Thank
Shij
MC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top