Databinding generic lists to Infragistics Webgrid

Published 6.22.2006 by ~mattg

Generics are awesome. I’ve noted a few reasons before (see the warm fuzzy blanket of type safety), so I won’t go into detail. For some reason, however, some generics are better than others.

On one of our selection pages, I defined a generic list which contains the type ModuleViewData

List<moduleviewdata>

. ModuleViewData is a super simple class…. It has a constructor and two member variables, along with two properties. That’s it, nothing special. One of my colleagues, while modifying some of our permission schemes to include Active Directory, simplified some of my code, and changed my list to a list of enum values

List<defaultview>

. DefaultView is just a standard enumeration, with an integer base.

That, apparently, breaks Infragistics data binding. I don’t know if it’s with the internal representation of a list of simple types or what, but neither the list of enums or a list of integers binds properly. The grid sets up ok, but the row initialization is never fired, despite the fact that two items are in the list and .DataBind() is being called.

So I had to put my super simple class back in, and it works fine. Let that be a lesson to those trying to simplify their code

Filed under .NET Development

Comments (4)

Comments RSS - Trackback - Write Comment

  1. Darrell Kress says:

    Reading over your issue, I would have some questions on your actual implementation of the List and how you are binding it to the WebGrid. From your description I tried making a simple Enum list and binding it both to the WebGrid and to a simple MS Grid View. I tried this both through an object datasource and through direct hook up to the getData’s resultant list. When I tried it to the WebGrid I didn’t get any results but then when I hooked it to the GridView I caught a few Microsoft exceptions. (System.Web.HttpException: The data source for GridView with id ‘GridView1′ did not have any properties or attributes from which to generate columns. Ensure that your data source has content.
    ).

    Since I really couldn’t tell what you were doing from the information you listed, I can’t tell if I am just following the same path you did or if you implemented something differently then I would have.

    Could you contact Infragistics Developer Support with a sample of what you are doing so that this issue can be investigated?

    Darrell Kress
    Infragistics Web Team

    public enum MySimpleEnum
    {
    FirstValue = 0,
    SecondValue = 1,
    ThirdValue = 2
    }

    public List SimpleEnumList = new List();

    public List getData()
    {
    SimpleEnumList.Add(SupportingClass.MySimpleEnum.SecondValue);
    SimpleEnumList.Add(SupportingClass.MySimpleEnum.FirstValue);
    SimpleEnumList.Add(SupportingClass.MySimpleEnum.ThirdValue);
    return SimpleEnumList;
    }

    Posted 6.28.2006 @ 12:49
  2. ~mattg says:

    Darrell,

    From your comment, I can’t tell if you are experiencing the same problem I am or not.

    Our application setup is atypical to what is considered “normal” by most component vendors. We derive our own class from your grid (as well as our own column class) and create everything at run time, not design time.

    I would note that I am not using the List but the List generic list, which may or may not have different underlying implementations. As I stated, my problem is that binding a List to the webgrid produces no output, despite the fact that I am setting up my own column, and overriding the InitializeRow event to handle the text generation. The problem is that my InitializeRow event doesn’t fire. If I replace the List with List in the example above, the InitializeRow event fires and everything is ok.

    Being that everything is ok, and our current dev cycle is ending in two days, I’d be hard pressed to make you an example. But if I find the time, I’ll submit one.

    Posted 6.29.2006 @ 06:42
  3. Dave Frank says:

    I realize I’m late to the party, but I just went through the exact same thing (though nothing to do with infragistics webgrid). I was trying to bind a generics list to a gridview and got the same message: (System.Web.HttpException: The data source for GridView with id ‘GridView1′ did not have any properties or attributes from which to generate columns. Ensure that your data source has content.
    Even though I added a columns tag and defined my own columns, I forgot to set “autogeneratecolumns=false”. Perhaps that was your problem as well? Oh well. I’m sure if this was in June you’ve forgotten all about it. :)

    Posted 12.09.2006 @ 02:46
  4. ~mattg says:

    Our grids are build on-the-fly using custom table format files that build the columns, so we’ve never had autogeneratecolumns on. While that may work for Gridview, it’s still an issue with the Infragistics UltraWebGrid, although we haven’t really investigated it in months, so they very well could have fixed it.

    Posted 12.13.2006 @ 19:02

Write Comment