Binding with a DataRelation

  • Thread starter Thread starter David D. McCrory
  • Start date Start date
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......
 
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
 
Back
Top