Bind a string collection to a data grid

P

Pete Nelson

Does anyone know of a way to bind a string collection to a datagrid?
Basically, I have an object, CreditPlans, and a string collection,
ModelNumbers. I'd like to bind the ModelNumbers collection to the
datagrid, but because there isn't a custom object with properties, just
a string object, I'm not sure how to reference it in the datagrid.

FYI, I can enumerate through the collection...

foreach(string modelNum in CreditPlan.ModelNumbers)
{
// code
}


But I'm not sure what would go in the datagrid....

<asp:DataGrid Runat="server" ID="dgModels" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="???"/>
</Columns>
</asp:DataGrid>


Any ideas? I can always create a custom ModelNumber object, but I'd
like to avoid it if I can.

--
===============================================================
Pete "DVDTracker" Nelson | When the barrel of my Glock
(e-mail address removed) | meets Hoppes #9, it's like
www.ecis.com/~weasel | a long-lost family reunion.
===============================================================
 
J

John Timney \(Microsoft MVP\)

you could probably just convert your string contents to an array and bind
directly to the array, as long as you could seperate out the items

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
 
P

Pete Nelson

Pete Nelson said:
<asp:DataGrid Runat="server" ID="dgModels" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="???"/>
</Columns>
</asp:DataGrid>

I found an answer.

<asp:TemplateColumn HeaderText="Model Numbers">
<ItemTemplate>
<%# Container.DataItem.ToString() %>
</ItemTemplate>
</asp:TemplateColumn>



--
===============================================================
Pete "DVDTracker" Nelson | When the barrel of my Glock
(e-mail address removed) | meets Hoppes #9, it's like
www.ecis.com/~weasel | a long-lost family reunion.
===============================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top