Simple generic list as a datasource for a grid

Discussion in 'ASP .Net' started by cowznofsky, Jul 12, 2007.

  1. cowznofsky

    cowznofsky Guest

    I'm getting data in a generic list class, which I'm not going to
    change. I would like to
    use it as a datasource for a datagrid or a gridview, but it doesn't
    implement IEnumerable.

    I'm wondering if there's a simple technique that would allow me to get
    the data into the datagrid.
    cowznofsky, Jul 12, 2007
    #1
    1. Advertising

  2. cowznofsky

    Fred Mertz Guest

    One option is to use the generic BindingList<T> class.

    http://msdn2.microsoft.com/en-us/library/ms132679.aspx#Mtps_DropDownFilterText





    "cowznofsky" <> wrote in message
    news:...
    > I'm getting data in a generic list class, which I'm not going to
    > change. I would like to
    > use it as a datasource for a datagrid or a gridview, but it doesn't
    > implement IEnumerable.
    >
    > I'm wondering if there's a simple technique that would allow me to get
    > the data into the datagrid.
    >
    Fred Mertz, Jul 12, 2007
    #2
    1. Advertising

  3. cowznofsky

    cowznofsky Guest

    On Jul 12, 3:35 pm, "Fred Mertz" <> wrote:
    > One option is to use the generic BindingList<T> class.
    >
    > http://msdn2.microsoft.com/en-us/library/ms132679.aspx#Mtps_DropDownF...
    >
    > "cowznofsky" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > I'm getting data in a generic list class, which I'm not going to
    > > change. I would like to
    > > use it as a datasource for a datagrid or a gridview, but it doesn't
    > > implement IEnumerable.

    >
    > > I'm wondering if there's a simple technique that would allow me to get
    > > the data into the datagrid.- Hide quoted text -

    >
    > - Show quoted text -


    Well, this looked to be just what I needed, but I haven't been able to
    get it to work.
    In the code below I have my original generic list, myColumns, and my
    BindingList, bColumns. I populate bColumns, and I confirm that I can
    get a value from the 'DB_Column_Name' property.
    Then I try to populate a dropdownlist box. Perhaps I may be using the
    wrong syntax here.
    But I also try to populate a datagrid, and get an error saying that
    'DB_Column_Name' is not found. If I try change the grid to
    AutoGenerateColumns="True", it still does not work.

    List<MasterColumnRecord> myColumns = wcc.Columns;

    BindingList<MasterColumnRecord> bColumns = new
    BindingList<MasterColumnRecord>();
    foreach (MasterColumnRecord mcr in myColumns)
    {
    bColumns.Add(mcr);
    }
    string test = bColumns[0].DB_Column_Name;

    SortList.DataSource = bColumns;
    SortList.DataMember = "DB_Column_Name";
    SortList.DataBind();

    DataGrid1.DataSource = bColumns;
    DataGrid1.DataBind();
    cowznofsky, Jul 12, 2007
    #3
  4. cowznofsky

    cowznofsky Guest

    On Jul 12, 4:10 pm, cowznofsky <> wrote:
    > On Jul 12, 3:35 pm, "Fred Mertz" <> wrote:
    >
    >
    >
    > > One option is to use the generic BindingList<T> class.

    >
    > >http://msdn2.microsoft.com/en-us/library/ms132679.aspx#Mtps_DropDownF...

    >
    > > "cowznofsky" <> wrote in message

    >
    > >news:...

    >
    > > > I'm getting data in a generic list class, which I'm not going to
    > > > change. I would like to
    > > > use it as a datasource for a datagrid or a gridview, but it doesn't
    > > > implement IEnumerable.

    >
    > > > I'm wondering if there's a simple technique that would allow me to get
    > > > the data into the datagrid.- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > Well, this looked to be just what I needed, but I haven't been able to
    > get it to work.
    > In the code below I have my original generic list, myColumns, and my
    > BindingList, bColumns. I populate bColumns, and I confirm that I can
    > get a value from the 'DB_Column_Name' property.
    > Then I try to populate a dropdownlist box. Perhaps I may be using the
    > wrong syntax here.
    > But I also try to populate a datagrid, and get an error saying that
    > 'DB_Column_Name' is not found. If I try change the grid to
    > AutoGenerateColumns="True", it still does not work.
    >
    > List<MasterColumnRecord> myColumns = wcc.Columns;
    >
    > BindingList<MasterColumnRecord> bColumns = new
    > BindingList<MasterColumnRecord>();
    > foreach (MasterColumnRecord mcr in myColumns)
    > {
    > bColumns.Add(mcr);
    > }
    > string test = bColumns[0].DB_Column_Name;
    >
    > SortList.DataSource = bColumns;
    > SortList.DataMember = "DB_Column_Name";
    > SortList.DataBind();
    >
    > DataGrid1.DataSource = bColumns;
    > DataGrid1.DataBind();


    Ok, I think I see part of my problem. "DB_Column_Name" was a public
    varable in the class. When I make it a property, the datagrid bind
    works.
    cowznofsky, Jul 12, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S2VubmV0aA==?=

    Easiest way to bind a grid datasource to a datatable

    =?Utf-8?B?S2VubmV0aA==?=, Jan 18, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    6,721
    =?Utf-8?B?S2VubmV0aA==?=
    Jan 18, 2004
  2. Murat Tasan
    Replies:
    1
    Views:
    8,037
    Chaitanya
    Feb 3, 2009
  3. Replies:
    2
    Views:
    432
  4. Polaris431
    Replies:
    2
    Views:
    486
    Chris Dollin
    Nov 9, 2006
  5. minlearn
    Replies:
    2
    Views:
    453
    red floyd
    Mar 13, 2009
Loading...

Share This Page