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

Binding to iEnumerable in Code-beind

2 Answers 74 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lisa
Top achievements
Rank 1
Lisa asked on 20 Sep 2011, 08:59 PM
Hi - I have a RadGridView that is currently using binding to the items source in .xaml.  I'd like to bind it in the code-behind instead, but can't seem to get the correct syntax. 

Here is the iEnum:
public IEnumerable<ctrlDistrictByDemographics_Result> DashboardDistrictByDemographics
        {
            get { return _spContext.ctrlDistrictByDemographics_Results; }
        }

And here is the .xaml
<telerik:RadGridView AutoExpandGroups="True" x:Name="chartDistrictByDemographics" ItemsSource="{Binding DashboardDistrictByDemographics}"
AutoGenerateColumns="False" IsReadOnly="True" CanUserFreezeColumns="False" CanUserSortColumns="False"
IsFilteringAllowed="False" CanUserSelect="False" RowIndicatorVisibility="Collapsed"
CanUserReorderColumns="False" CanUserResizeColumns="False" ShowGroupPanel="False" CanUserDeleteRows="False" >
It's this that I'm trying to get in the C# code-behind:

ItemsSource

 

 

="{Binding DashboardDistrictByDemographics}"

 


Thanks for any help.

2 Answers, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 21 Sep 2011, 03:47 PM
Hello Lisa,

I believe that this topic explains it. 

But you could easily just do this:

this.chartDistrictByDemographics.ItemsSource = DashboardDistrictByDemographics;

since you are doing it in code-behind, you really don't have to use a Binding.

All the best,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Lisa
Top achievements
Rank 1
answered on 21 Sep 2011, 04:05 PM
Thanks!  I had tried to just set the item source as you have but was getting errors.  The issue was that the iEnumerable was in a view model, so by adding the view model it works!

this

 

 

.chartDistrictByDemographics.ItemsSource = DistrictByDemographicsModel.DashboardDistrictByDemographics;

 

Tags
GridView
Asked by
Lisa
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Lisa
Top achievements
Rank 1
Share this question
or