Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Simple generic list as a datasource for a grid

Reply
Thread Tools

Simple generic list as a datasource for a grid

 
 
cowznofsky
Guest
Posts: n/a
 
      07-12-2007
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.

 
Reply With Quote
 
 
 
 
Fred Mertz
Guest
Posts: n/a
 
      07-12-2007
One option is to use the generic BindingList<T> class.

http://msdn2.microsoft.com/en-us/lib...DownFilterText





"cowznofsky" <> wrote in message
news: ps.com...
> 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.
>



 
Reply With Quote
 
 
 
 
cowznofsky
Guest
Posts: n/a
 
      07-12-2007
On Jul 12, 3:35 pm, "Fred Mertz" <A...@B.COM> wrote:
> One option is to use the generic BindingList<T> class.
>
> http://msdn2.microsoft.com/en-us/lib...Mtps_DropDownF...
>
> "cowznofsky" <jhco...@yahoo.com> wrote in message
>
> news: ps.com...
>
>
>
> > 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();

 
Reply With Quote
 
cowznofsky
Guest
Posts: n/a
 
      07-12-2007
On Jul 12, 4:10 pm, cowznofsky <jhco...@yahoo.com> wrote:
> On Jul 12, 3:35 pm, "Fred Mertz" <A...@B.COM> wrote:
>
>
>
> > One option is to use the generic BindingList<T> class.

>
> >http://msdn2.microsoft.com/en-us/lib...Mtps_DropDownF...

>
> > "cowznofsky" <jhco...@yahoo.com> wrote in message

>
> >news: ups.com...

>
> > > 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
generic interfaces with generic methods Murat Tasan Java 1 02-03-2009 12:17 PM
How do you reference this property: System.Collections.Generic.ICollection<DataSource> Polaris431 C Programming 2 11-09-2006 11:08 AM
Generic class in a non generic class nramnath@gmail.com Java 2 07-04-2006 07:24 AM
XML FILE as datasource to Grid view..? not able to remove the nodes..? =?iso-8859-1?Q?=BF_Mahesh_Kumar?= ASP .Net 0 10-14-2005 10:47 AM
Easiest way to bind a grid datasource to a datatable =?Utf-8?B?S2VubmV0aA==?= ASP .Net 2 01-18-2004 12:16 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57