473,778 Members | 1,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Mode lNumbers)
{
// code
}
But I'm not sure what would go in the datagrid....

<asp:DataGrid Runat="server" ID="dgModels" AutoGenerateCol umns="False">
<Columns>
<asp:BoundColum n 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 2101
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_auth or_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_autho r_plug>
----------------------------------------------

"Pete Nelson" <we****@ecis.co m> wrote in message
news:r5******** *************** *********@4ax.c om...
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.Mode lNumbers)
{
// code
}
But I'm not sure what would go in the datagrid....

<asp:DataGrid Runat="server" ID="dgModels" AutoGenerateCol umns="False">
<Columns>
<asp:BoundColum n 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.co m> wrote:
<asp:DataGri d Runat="server" ID="dgModels" AutoGenerateCol umns="False">
<Columns>
<asp:BoundColum n DataField="???"/>
</Columns>
</asp:DataGrid>


I found an answer.

<asp:TemplateCo lumn HeaderText="Mod el Numbers">
<ItemTemplate >
<%# Container.DataI tem.ToString() %>
</ItemTemplate>
</asp:TemplateCol umn>

--
=============== =============== =============== =============== ===
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
1229
by: Julia | last post by:
class Document { Hashtable Properties ; //Key is the property name } class Media { Document document;
1
1717
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
1404
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 are static in that they will not be updated they are just for viewing I have everything working but not to perfection
2
2073
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 DataTable("Total") ' Add two columns
1
2952
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 property name, when I try to bind it to the grid.. now, here is where it gets tricky. Do I NEED to Implement IBindingList, on my collection object, since my object that I am adding to the collection inherits from a another class? here is my...
11
2499
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 to the DataTable. The code for this is lengthy and the grid is obviously not editable. I've read it's possible to connect my collection directly, and have it be editable, too. Can anyone point me to a resource that can walk me through this? ...
3
1353
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 x). If I make a private list as list(of x) in a class and implements IList(of x) I can control what methods to be public. I works - but now I can't bind the collection to a listbox og grid (it says something about complex datatype).
3
9579
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 data. ArrayList ar = new ArrayList(); // To store more than one customer object. for (int x = 0; x < 30; x++) { custdata = new Customer();
1
1340
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 Collection, it seems like it overwrites the other ArticleAttributes. When bind the ArticleAttributeCollection to a datagrid, all articleattributes are the same. This is what my datagrid dispays: ID Content
0
9465
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10068
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7474
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2863
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.