473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.DataSourde = list;
gridview1.DataBind();

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

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 34924
Hi Steven,

When I bind custom collections to GridViews, I use the following:
<asp:BoundField DataField="State" HeaderText="State"></asp:BoundField>

or:

<asp:TemplateField HeaderText="State">
<ItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.State") %>
</ItemTemplate>
</asp:TemplateField>

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*******@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Hi Steven,

When I bind custom collections to GridViews, I use the following:
<asp:BoundField DataField="State" HeaderText="State"></asp:BoundField>

or:

<asp:TemplateField HeaderText="State">
<ItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.State") %>
</ItemTemplate>
</asp:TemplateField>

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:BoundField DataField="Item.ExpirationDate" HeaderText="Expiration Date"
/>

Right now I'm getting:

A field or property with the name 'Item.ExpirationDate' was not found on the
selected data source.
"Tod Birdsall, MCSD for .NET" <tb*******@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Hi Steven,

When I bind custom collections to GridViews, I use the following:
<asp:BoundField DataField="State" HeaderText="State"></asp:BoundField>

or:

<asp:TemplateField HeaderText="State">
<ItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.State") %>
</ItemTemplate>
</asp:TemplateField>

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:BoundField DataField="ExpirationDate" HeaderText="Expiration
Date"/>

or maybe this:

<asp:TemplateField HeaderText="Expiration Date">
<ItemTemplate>
<%# Eval("ExpirationDate") %>
</ItemTemplate>
</asp:TemplateField>

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:BoundField DataField="Item.ExpirationDate" HeaderText="Expiration Date"
/>

Right now I'm getting:

A field or property with the name 'Item.ExpirationDate' was not found on the
selected data source.
"Tod Birdsall, MCSD for .NET" <tb*******@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Hi Steven,

When I bind custom collections to GridViews, I use the following:
<asp:BoundField DataField="State" HeaderText="State"></asp:BoundField>

or:

<asp:TemplateField HeaderText="State">
<ItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.State") %>
</ItemTemplate>
</asp:TemplateField>

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
ShoppingMetaElement object :-)

I found this working Text= '<%# Eval("Item.ExpirationDate") %>' 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*********************@z14g2000cwz.googlegro ups.com...
It sounds like this should work, no?

<asp:BoundField DataField="ExpirationDate" HeaderText="Expiration
Date"/>

or maybe this:

<asp:TemplateField HeaderText="Expiration Date">
<ItemTemplate>
<%# Eval("ExpirationDate") %>
</ItemTemplate>
</asp:TemplateField>

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:BoundField DataField="Item.ExpirationDate" HeaderText="Expiration
Date"
/>

Right now I'm getting:

A field or property with the name 'Item.ExpirationDate' was not found on
the
selected data source.
"Tod Birdsall, MCSD for .NET" <tb*******@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
> Hi Steven,
>
> When I bind custom collections to GridViews, I use the following:
> <asp:BoundField DataField="State" HeaderText="State"></asp:BoundField>
>
> or:
>
> <asp:TemplateField HeaderText="State">
> <ItemTemplate>
> <%# DataBinder.Eval(Container, "DataItem.State") %>
> </ItemTemplate>
> </asp:TemplateField>
>
> 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
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...
1
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...
2
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...
0
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...
0
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...
0
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 ...
7
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...
2
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...

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.