Monday, August 27, 2012

Subcollection Binding in a DataGrid

Subcollection Binding in a DataGrid

I want to show a datagroid with a collection containing a sub collection. for example

Name  Address  Vacant

xx          xx             xx

            xxx

          xxxxx

             xx

 

I have 1 table containing Employee which contains 3 fields 1. Name, AddressID(Foreign Key), IsVacant

I have another table called Address which contains 4 Fields 1. AddressID(PK), Street1, Street2, City, State

Now in the DataGrid I have 3 Columns 1. Name 2. Address 3. IsVacant.  I am able to show Name and IsVacanat column in the DataGrid

I dont know how to show the Address column in the Datagrid

Any help would be useful. Please let me know if i can do this in any other way..

 

Answers & Comments...

Answer: 1

GaneshGdrBlr

Any help would be useful. Please let me know if i can do this in any other way..

I will give you two ways.

1. You can display the address in a single column seperated by comma Ex : Dravid,Newyork,US

2. Display the complete address in RowDetailsTemplate.



Answer: 2

syed amjad

 I will give you two ways.

1. You can display the address in a single column seperated by comma Ex : Dravid,Newyork,US

2. Display the complete address in RowDetailsTemplate.

I dont want to use as a single column

But i am not sure how to use it with RowDetailsTemplate

Code sample would be more helpful

 



Answer: 3

Hi,

First you should retrieve all information (including Name, Street1, Street2, City, State and IsVacant) and set it as ItemsSource of the DataGrid control. Then you can use RowDetailsTemplate (or you can use DataGrid.Columns)and IValueConverter to make it work. Below is some links for you:

http://www.codeproject.com/Tips/234337/Data-Binding-Using-IValueConverter-in-Silverlight 

http://www.silverlightshow.net/items/Data-Conversion-in-Silverlight-2-Data-Binding.aspx 

Best Regards,





No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog