473,405 Members | 2,300 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,405 software developers and data experts.

Bind a string collection to a data grid

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
we****@ecis.com | meets Hoppes #9, it's like
www.ecis.com/~weasel | a long-lost family reunion.
================================================== =============
Nov 17 '05 #1
2 2075
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" <we****@ecis.com> wrote in message
news:r5********************************@4ax.com...
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
we****@ecis.com | meets Hoppes #9, it's like
www.ecis.com/~weasel | a long-lost family reunion.
================================================== =============

Nov 17 '05 #2
Pete Nelson <we****@ecis.com> wrote:
<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
we****@ecis.com | meets Hoppes #9, it's like
www.ecis.com/~weasel | a long-lost family reunion.
================================================== =============
Nov 17 '05 #3

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

Similar topics

4
by: Julia | last post by:
class Document { Hashtable Properties ; //Key is the property name } class Media { Document document;
1
by: yaniv abo | last post by:
Hello. How can I bind a list of objects to a DataGird? I have a custom collection of Customer class
0
by: Steve | last post by:
Hi I have a db with 2 tables that I want to bind to a grid depending on a selection in a Dropdownlist Also I want to be able to select a row from the gris to fill some textboxes. The databases...
2
by: Kenneth | last post by:
Hi, I want to make sure I got the easiest way on how to bind a grid's datasource to a datatable. I've made an in-memory datatable Dim dtTotal As DataTable Dim drow As DataRow dtTotal = New...
1
by: Doug D via .NET 247 | last post by:
I really really need some insight on this problem I am trying to bind a strongly typed collection object to a datagrid. I already Inherited CollectionBase, but .NET says that it cannot find my...
11
by: Michael Kellogg | last post by:
I have a collection of custom objects that I am displaying in a Windows Forms Datagrid. To display it, I take the collection and build a DataTable object on the fly, then set the grid's DataSource...
3
by: Michael Fällgreen | last post by:
Hi, I need to make a strongly typed collection of x, and the simplets way is to inherits list(of x). With that I can bind to a list-control. However - i don't need all the methods from list(of...
3
by: vineetbatta | last post by:
I have Custom Data class which stores data about single customer and then i store that customer objects in arraylist as shown below. Customer custdata = null; // Custom Data class for 1 customer...
1
by: Øyvind Isaksen | last post by:
I try to make my own ArticleAttribute object and ArticleAttributeCollection, and add data to this Collection. It almost works, but the problem is that each time I add an ArticleAttribute to my...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.