Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Simple generic list as a datasource for a grid

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cowznofsky - 12 Jul 2007 19:44 GMT
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 - 12 Jul 2007 20:35 GMT
One option is to use the generic BindingList<T> class.

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

> I'm getting data in a generic list class, which I'm not going to
> change.  I would like to
[quoted text clipped - 3 lines]
> I'm wondering if there's a simple technique that would allow me to get
> the data into the datagrid.
cowznofsky - 12 Jul 2007 21:10 GMT
> One option is to use the generic BindingList<T> class.
>
[quoted text clipped - 9 lines]
>
> - 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 - 12 Jul 2007 21:34 GMT
> > One option is to use the generic BindingList<T> class.
>
[quoted text clipped - 41 lines]
>                 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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.