Binding Data With Unknown Column Count

4 posts, 0 answers
  1. Andrew
    Andrew avatar
    104 posts
    Member since:
    May 2008

    Posted 22 Jul 2009 Link to this post

    I have data that is generated based on a myriad of user data from a database, and I've notice that most of the samples for binding data to the GridView require that you know the column names and count in order to create an object that represents a given collection of data. You have to create an object as a List<> or ObservableCollection.

    Is there a way to bind data whosse makeup you have no knowledge of at runtime?

  2. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 23 Jul 2009 Link to this post

    Hi Andrew,

    You may try to build dynamically DataTable with the incoming data. You can add so many DataColumns as "columns" you get.
  3. DevCraft R3 2016 release webinar banner
  4. Milan
    Milan avatar
    1989 posts

    Posted 23 Jul 2009 Link to this post

    Hello Andrew,

    You could try using the lightweight DataTable that Vladimir Enchev has implemented. You can find more information about it here:

    All the best,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 23 Jul 2009 Link to this post

    Oops, I forgot that DataSet, DataTable and so on are not present in Silverlight... I did a similar thing in a project a few months ago and I solved it using the System.Reflection.Emit namespace. That means creating a new type dynamically. In Visual Studio documentation you can find a very good, and easy (despite at first time it sounds tediuos) example.

    Another issue you, maybe, will have to face is about templating the cells in each column, I suggest to use the XamlReader.Load() method to load dynamically the cell styles.

    Hope this helps
Back to Top