Binding to iEnumerable in Code-beind

3 posts, 1 answers
  1. Lisa
    Lisa avatar
    35 posts
    Member since:
    May 2011

    Posted 20 Sep 2011 Link to this post

    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:




    ="{Binding DashboardDistrictByDemographics}"


    Thanks for any help.

  2. Answer
    Rossen Hristov
    Rossen Hristov avatar
    2478 posts

    Posted 21 Sep 2011 Link to this post

    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,
    the Telerik team

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

  3. Lisa
    Lisa avatar
    35 posts
    Member since:
    May 2011

    Posted 21 Sep 2011 Link to this post

    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!




    .chartDistrictByDemographics.ItemsSource = DistrictByDemographicsModel.DashboardDistrictByDemographics;


Back to Top