This is a migrated thread and some comments may be shown as answers.

[Solved] DataBinding Issue Inside telerik details column

7 Answers 112 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alex
Top achievements
Rank 1
Alex asked on 23 Sep 2010, 02:13 PM
Hi,
I have a telerik gridview for which I created a  row details column. the details template looks smth like this


<telerik:RadGridView.RowDetailsTemplate>
<DataTemplate>
<Grid>
<Grid Margin="0,0,0,0" HorizontalAlignment="Left" Width="80" Height="155" VerticalAlignment="Top">
        <Rectangle Fill="Gray" Height="21" Stroke="Black" VerticalAlignment="Top"/>
        <sdk:Label HorizontalAlignment="Right" Height="13" Margin="0,6,5,0" VerticalAlignment="Top" Width="auto"  Content="Description"/>
<telerik:RadGridView Margin="0,20,0,0" ShowColumnHeaders="True" ShowGroupPanel="False" ItemsSource="{Binding GridProvisions}" RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False" VerticalAlignment="Top">
        <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Width="*"  Header="Total" DataMemberBinding="{Binding Total, Mode=OneWay}" TextAlignment="Center"  IsReadOnly="True" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>


and so on...

The problem is that the data won't bind.
If I place the same grid outside the details column it works perfectly. Maybe I'm missing something, I'm new to silverlight.
I have the same problem with a rad combo box placed inside a gridview celltemplate.

I apreciate if someone could help, I'm stuck.

Thanks.

7 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 23 Sep 2010, 02:23 PM
Hello Alex,

 The DataContext of the inner control is actually the parent data item. This code:

ItemsSource="{Binding GridProvisions}" 

will look for property GridProvisions on the parent data item - most probably you do not have such. 

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alex
Top achievements
Rank 1
answered on 23 Sep 2010, 05:42 PM
I'm glad to see te post works now, but I didn't get an answer how should I acces my Datasource from outside the parent?

I saw an example which looked like this
ItemsSource={Binding DataContext.GridProvisions ElementName=LayoutRoot}
but didn't seam to work for me.
Any Ideas? I don't know how to fix this


Thanks,
Alex
0
Yavor Georgiev
Telerik team
answered on 23 Sep 2010, 05:48 PM
Hi Alex,

 Unfortunately, Silverlight does not support bindings like the one you saw. You will need to either expose your ViewModel as a StatisResource and reference it from the Binding's Source property, or use a DataContextProxy.

Greetings,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alex
Top achievements
Rank 1
answered on 23 Sep 2010, 05:55 PM
Hi Yavor,

I will try your suggestion.
Thanks for your support so far.

Alex

0
Alex
Top achievements
Rank 1
answered on 24 Sep 2010, 10:19 AM
Hi again,

I've created a DataContextProxy  just like here 
http://weblogs.asp.net/dwahlin/archive/2009/08/20/creating-a-silverlight-datacontext-proxy-to-simplify-data-binding-in-nested-controls.aspx

And now my code looks like this 

<sdk:Page.Resources>
<local:AppDataSource x:Key="AppDataSourceDataSource" d:IsDataSource="True"/>
<local:DataContextProxy x:Key="DataContextProxy" />
</sdk:Page.Resources>


<telerik:RadGridView Margin="0,20,0,0" ShowColumnHeaders="True" ShowGroupPanel="False"

ItemsSource="{Binding Source={StaticResource DataContextProxy},Path=DataSource.GridProvisions}"

RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False" VerticalAlignment="Top">
             <telerik:RadGridView.Columns>
             <telerik:GridViewDataColumn Width="*"  Header="Total" DataMemberBinding="{Binding Total, Mode=OneWay}" TextAlignment="Center"  IsReadOnly="True" />
             </telerik:RadGridView.Columns>
             </telerik:RadGridView>

The problem is it  still won't bind.

Have I done something wrong? I'm out of ideeas. Any help is welcomed.

Thanks,
Alex
0
Yavor Georgiev
Telerik team
answered on 24 Sep 2010, 11:44 AM
Hello Alex,

 Does the DataContextProxy receive the proper DataContext?

All the best,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alex
Top achievements
Rank 1
answered on 24 Sep 2010, 01:36 PM
Hi Yavor,

It seamed that altough the DataContext  for the Proxy was set from this.DataContext which I assume is the page data context (which I set it after initializecomponent() with my data source  
LayoutRoot.Datacontext =  ViewModel.m_AppDataSource;)

didn't took it .

However I directly set the datacontext in class definition  with my DataSource and it populates just fine now.

Thanks a lot!
Tags
GridView
Asked by
Alex
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Alex
Top achievements
Rank 1
Yavor Georgiev
Telerik team
Share this question
or