By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,903 Members | 1,677 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,903 IT Pros & Developers. It's quick & easy.

Bind GridView to generic custom object List collection

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a

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

P: n/a

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

P: n/a
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

P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.