473,779 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bind GridView to generic custom object List collection

Hi!,

I have defined a List<T> like this List<Container>
Container class holds my Item object and it's state as a Enum.

Container.Item
Container.State

I would like to bind it to GridView.

gridview1.DataS ourde = list;
gridview1.DataB ind();

Problem is that I can't get it to show the data. I try:
<asp:BoundFie ld DataField="Item .Name" HeaderText="Nam e" />

but I'm getting an error saying that Item doesn't exist.

Right now I'm using DataSet but I would like to use my business object's
collection.

Best regards,

Steven
Nov 19 '05 #1
5 34944
Hi Steven,

When I bind custom collections to GridViews, I use the following:
<asp:BoundFie ld DataField="Stat e" HeaderText="Sta te"></asp:BoundField>

or:

<asp:TemplateFi eld HeaderText="Sta te">
<ItemTemplate >
<%# DataBinder.Eval (Container, "DataItem.State ") %>
</ItemTemplate>
</asp:TemplateFie ld>

The above assumes that your custom collection contains an has a
"State" property that returns a string.

Hope this helps.

Tod Birdsall, MCSD for .NET
blog: http://tod1d.blogspot.com

Nov 19 '05 #2

Thanks for the reply. I have to check is, in my case, Item an property. It
might be a public variable.
"Tod Birdsall, MCSD for .NET" <tb*******@gmai l.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Hi Steven,

When I bind custom collections to GridViews, I use the following:
<asp:BoundFie ld DataField="Stat e" HeaderText="Sta te"></asp:BoundField>

or:

<asp:TemplateFi eld HeaderText="Sta te">
<ItemTemplate >
<%# DataBinder.Eval (Container, "DataItem.State ") %>
</ItemTemplate>
</asp:TemplateFie ld>

The above assumes that your custom collection contains an has a
"State" property that returns a string.

Hope this helps.

Tod Birdsall, MCSD for .NET
blog: http://tod1d.blogspot.com

Nov 19 '05 #3

well it wasn't a property. Now I can access the 'Item' object.
How can I access further - the ExpirationDate property of the Item object?

is something like that valid?
<asp:BoundFie ld DataField="Item .ExpirationDate " HeaderText="Exp iration Date"
/>

Right now I'm getting:

A field or property with the name 'Item.Expiratio nDate' was not found on the
selected data source.
"Tod Birdsall, MCSD for .NET" <tb*******@gmai l.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Hi Steven,

When I bind custom collections to GridViews, I use the following:
<asp:BoundFie ld DataField="Stat e" HeaderText="Sta te"></asp:BoundField>

or:

<asp:TemplateFi eld HeaderText="Sta te">
<ItemTemplate >
<%# DataBinder.Eval (Container, "DataItem.State ") %>
</ItemTemplate>
</asp:TemplateFie ld>

The above assumes that your custom collection contains an has a
"State" property that returns a string.

Hope this helps.

Tod Birdsall, MCSD for .NET
blog: http://tod1d.blogspot.com

Nov 19 '05 #4
It sounds like this should work, no?

<asp:BoundFie ld DataField="Expi rationDate" HeaderText="Exp iration
Date"/>

or maybe this:

<asp:TemplateFi eld HeaderText="Exp iration Date">
<ItemTemplate >
<%# Eval("Expiratio nDate") %>
</ItemTemplate>
</asp:TemplateFie ld>

Mike

Steven Baggs wrote:
well it wasn't a property. Now I can access the 'Item' object.
How can I access further - the ExpirationDate property of the Item object?

is something like that valid?
<asp:BoundFie ld DataField="Item .ExpirationDate " HeaderText="Exp iration Date"
/>

Right now I'm getting:

A field or property with the name 'Item.Expiratio nDate' was not found on the
selected data source.
"Tod Birdsall, MCSD for .NET" <tb*******@gmai l.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Hi Steven,

When I bind custom collections to GridViews, I use the following:
<asp:BoundFie ld DataField="Stat e" HeaderText="Sta te"></asp:BoundField>

or:

<asp:TemplateFi eld HeaderText="Sta te">
<ItemTemplate >
<%# DataBinder.Eval (Container, "DataItem.State ") %>
</ItemTemplate>
</asp:TemplateFie ld>

The above assumes that your custom collection contains an has a
"State" property that returns a string.

Hope this helps.

Tod Birdsall, MCSD for .NET
blog: http://tod1d.blogspot.com


Nov 19 '05 #5

ExpirationDate is a property of the Item object which is a property of a
ShoppingMetaEle ment object :-)

I found this working Text= '<%# Eval("Item.Expi rationDate") %>' in the
TemplateField.

Seems impossible in DataBound column.

BTW: MSDN beta documentation of ASP.NET has a lot of bugs.
"xhead" <xh******@gmail .com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
It sounds like this should work, no?

<asp:BoundFie ld DataField="Expi rationDate" HeaderText="Exp iration
Date"/>

or maybe this:

<asp:TemplateFi eld HeaderText="Exp iration Date">
<ItemTemplate >
<%# Eval("Expiratio nDate") %>
</ItemTemplate>
</asp:TemplateFie ld>

Mike

Steven Baggs wrote:
well it wasn't a property. Now I can access the 'Item' object.
How can I access further - the ExpirationDate property of the Item
object?

is something like that valid?
<asp:BoundFie ld DataField="Item .ExpirationDate " HeaderText="Exp iration
Date"
/>

Right now I'm getting:

A field or property with the name 'Item.Expiratio nDate' was not found on
the
selected data source.
"Tod Birdsall, MCSD for .NET" <tb*******@gmai l.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
> Hi Steven,
>
> When I bind custom collections to GridViews, I use the following:
> <asp:BoundFie ld DataField="Stat e" HeaderText="Sta te"></asp:BoundField>
>
> or:
>
> <asp:TemplateFi eld HeaderText="Sta te">
> <ItemTemplate >
> <%# DataBinder.Eval (Container, "DataItem.State ") %>
> </ItemTemplate>
> </asp:TemplateFie ld>
>
> The above assumes that your custom collection contains an has a
> "State" property that returns a string.
>
> Hope this helps.
>
> Tod Birdsall, MCSD for .NET
> blog: http://tod1d.blogspot.com
>

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1833
by: Frank Wisniewski | last post by:
Hi All, I have created my own generic comparer object which implements IComparer and uses reflection. I have tested it and it seem to work fine but I am worried about the way I did it. My goal was to not have to make a seperate Comparer class for every field of my object that I wanted to sort like the ASP.net TimeTracker starter kit did. My Code is below. Basically to use it all I have to do is to Create the GenericComparer object,...
1
2665
by: Weston Weems | last post by:
I've got a collection of objects say fruit. and fruit has a fairly decent heirachial structure not just flat props. I've got my repeater to bind to my fruit collection just fine, but what I want to do is actually be able to view specific properties in my repeaters template. Here's what I've got so far, which is being exectued for each row in the repeater. My problem is that for whatever reason I cant cast DataItem to Fruit. Can
2
2209
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple properties, ProdID, Description, Quantity and UPC. 3 strings and a long. The LineItemsCollection class inherits from System.Collections.Specialized.NameObjectCollectionBase. It also implements both IEnumerable and IList.
0
1171
by: a | last post by:
I have a custom object that inherits from CollectionBase and it does not successfully bind to GridViews or DropdownLists. My understanding is that that is because GridViews and Dropdownlists implement IEnumerable, therefore, if I want my custom object to bind to the gridview or the dropdownlist, I need to inherit from IEnumerable also, right? Whatever the answer is, I'm trying to learn what I need to do to get my custom object to bind to...
0
1955
by: a | last post by:
Q. Unable to get a Profile custom (object) collection to bind to GridView,etc (IList objects)? This is my first custom object so I may be doing something rather simple, wrong, or it may be something else to do with the Profile object. Either way, I need help Here's a brief description of the code----------------------------------------------------------------------------------
0
1836
by: a | last post by:
I need to create an instance of a custom object 'School.Teacher' and use it in a Profile object. I'm developing a bad case of "Pretzel Logic" thinking about this. Filling the custom object 'School.Teacher' as an ArrayList creates the proper information (see aspx code below), but I'm unable to use this ArrayList in the Profile object. The aspx code below shows the attempt and error message.
7
1691
by: a | last post by:
If the code to insert a new Student is: Profile.Teachers.Classes.Students.Add(new TCS.Student(id,teacher, class, name)); what is the code to Remove a student? I tried the code below, but I don't understand the syntax: Profile.Teachers.Classes.Students.Remove(new TCS.Student(name));// This line fails
2
8992
by: Greg | last post by:
Hello, I am trying to bind a GridView to a custom object I have created. First, here is what I'm trying to do: I have a wizard for adding/editing Users. When the wizard begins, a User object (custom class) is created, and properties are populated in each step of the wizard. In one of the steps, the User is assigned to 1 or more Programs. Assigned Programs are stored by the User object in a List, and displayed in a GridView in the...
1
1602
by: =?Utf-8?B?Q2hhcmxlcw==?= | last post by:
I'm running VS2008 & attempting to solve a problem I've encountered while developing some software for our business. Here's the basic idea...I've created a class that represents a file (with members such as file name, file location, and a string containing the files data). Each file object also contains an ArrayList of another custom object I've created--a field object (which is basically two fields--field name & field data). These...
0
9632
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10302
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.