Bind a string collection to a data grid

  • Thread starter Thread starter Pete Nelson
  • Start date Start date
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.
===============================================================
 
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>
 
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.
===============================================================
 
Back
Top