473,659 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Collection problems (create Collection object, add data to collection, bind collection to datagrid)

I try to make my own ArticleAttribut e object and ArticleAttribut eCollection,
and add data to this Collection. It almost works, but the problem is that
each time I add an ArticleAttribut e to my Collection, it seems like it
overwrites the other ArticleAttribut es. When bind the
ArticleAttribut eCollection to a datagrid, all articleattribut es are the
same.

This is what my datagrid dispays:

ID Content
2 Hello 2
2 Hello 2
2 Hello 2

It should be like this:

ID Content
0 Hello 0
1 Hello 1
2 Hello 2

-----------------------------------------------
Here is my ArticleAttribut eCollection.cs
-----------------------------------------------

namespace Test
{
[Serializable()]
public class ArticleAttribut eCollection : CollectionBase, IEnumerable
{

public void Insert(int index, ArticleAttribut e ArticleAttribut e)
{
base.List.Inser t(index, ArticleAttribut e);
}

public void Add(ArticleAttr ibute ArticleAttribut e)
{
base.List.Add(A rticleAttribute );
}

public void Remove(ArticleA ttribute ArticleAttribut e)
{
base.List.Remov e(ArticleAttrib ute);
}

public ArticleAttribut e this[int index]
{
get
{
return (ArticleAttribu te)(base.List[index]);
}
set
{
base.List[index] = value;
}
}

}
}

-----------------------------------------------
Here is my ArticleAttribut e.cs
-----------------------------------------------

namespace Test
{
public class ArticleAttribut e
{

public ArticleAttribut e()
{
}

public ArticleAttribut e(int templateDefinit ionId, int articleId,
string content, string templateDefinit ionName, string
templateDefinit ionHelpText)
{
this._TemplateD efinitionId = templateDefinit ionId;
this.ArticleId = articleId;
this.Content = content;
this.TemplateDe finitionName = templateDefinit ionName;
this.TemplateDe finitionHelpTex t = templateDefinit ionHelpText;
}

private int _TemplateDefini tionId;
public int TemplateDefinit ionId
{
get { return _TemplateDefini tionId; }
set { _TemplateDefini tionId = value; }
}

private int _ArticleId;
public int ArticleId
{
get { return _ArticleId; }
set { _ArticleId = value; }
}

private string _Content;
public string Content
{
get { return _Content; }
set { _Content = value; }
}

private string _TemplateDefini tionName;
public string TemplateDefinit ionName
{
get { return _TemplateDefini tionName; }
set { _TemplateDefini tionName = value; }
}

private string _TemplateDefini tionHelpText;
public string TemplateDefinit ionHelpText
{
get { return _TemplateDefini tionHelpText; }
set { _TemplateDefini tionHelpText = value; }
}

}
}
-----------------------------------------------
Here I adds articleAttribut es to the Collection, and bind it to a datagrid.
It returns 3 items, all with the same ID and Content... Why??
-----------------------------------------------

protected void Page_Load(objec t sender, EventArgs e)
{
Test.ArticleAtt ributeCollectio n ArticleAttribut eCollection = new
Test.ArticleAtt ributeCollectio n();
Test.ArticleAtt ribute ArticleAttribut e = new Test.ArticleAtt ribute();

int i = 0;

while (i<2)
{
ArticleAttribut e.ArticleId = i;
ArticleAttribut e.Content = "Innhold " + i;
ArticleAttribut eCollection.Add (ArticleAttribu te);
i++;
}

Response.Write( ArticleAttribut eCollection.Cou nt);

this.dtgTest.Da taSource = ArticleAttribut eCollection;
this.dtgTest.Da taBind();
}
WHAT IS WRONG IN MY CODE???
May 18 '07 #1
1 1333
I got it, I was missing this:
ArticleAttribut e = new Test.ArticleAtt ribute(); // create a new
object
"Øyvind Isaksen" <oy****@webress urs.nowrote in message
news:uR******** ******@TK2MSFTN GP05.phx.gbl...
>I try to make my own ArticleAttribut e object and
ArticleAttribu teCollection, and add data to this Collection. It almost
works, but the problem is that each time I add an ArticleAttribut e to my
Collection, it seems like it overwrites the other ArticleAttribut es. When
bind the ArticleAttribut eCollection to a datagrid, all articleattribut es
are the same.

This is what my datagrid dispays:

ID Content
2 Hello 2
2 Hello 2
2 Hello 2

It should be like this:

ID Content
0 Hello 0
1 Hello 1
2 Hello 2

-----------------------------------------------
Here is my ArticleAttribut eCollection.cs
-----------------------------------------------

namespace Test
{
[Serializable()]
public class ArticleAttribut eCollection : CollectionBase, IEnumerable
{

public void Insert(int index, ArticleAttribut e ArticleAttribut e)
{
base.List.Inser t(index, ArticleAttribut e);
}

public void Add(ArticleAttr ibute ArticleAttribut e)
{
base.List.Add(A rticleAttribute );
}

public void Remove(ArticleA ttribute ArticleAttribut e)
{
base.List.Remov e(ArticleAttrib ute);
}

public ArticleAttribut e this[int index]
{
get
{
return (ArticleAttribu te)(base.List[index]);
}
set
{
base.List[index] = value;
}
}

}
}

-----------------------------------------------
Here is my ArticleAttribut e.cs
-----------------------------------------------

namespace Test
{
public class ArticleAttribut e
{

public ArticleAttribut e()
{
}

public ArticleAttribut e(int templateDefinit ionId, int articleId,
string content, string templateDefinit ionName, string
templateDefinit ionHelpText)
{
this._TemplateD efinitionId = templateDefinit ionId;
this.ArticleId = articleId;
this.Content = content;
this.TemplateDe finitionName = templateDefinit ionName;
this.TemplateDe finitionHelpTex t = templateDefinit ionHelpText;
}

private int _TemplateDefini tionId;
public int TemplateDefinit ionId
{
get { return _TemplateDefini tionId; }
set { _TemplateDefini tionId = value; }
}

private int _ArticleId;
public int ArticleId
{
get { return _ArticleId; }
set { _ArticleId = value; }
}

private string _Content;
public string Content
{
get { return _Content; }
set { _Content = value; }
}

private string _TemplateDefini tionName;
public string TemplateDefinit ionName
{
get { return _TemplateDefini tionName; }
set { _TemplateDefini tionName = value; }
}

private string _TemplateDefini tionHelpText;
public string TemplateDefinit ionHelpText
{
get { return _TemplateDefini tionHelpText; }
set { _TemplateDefini tionHelpText = value; }
}

}
}
-----------------------------------------------
Here I adds articleAttribut es to the Collection, and bind it to a
datagrid.
It returns 3 items, all with the same ID and Content... Why??
-----------------------------------------------

protected void Page_Load(objec t sender, EventArgs e)
{
Test.ArticleAtt ributeCollectio n ArticleAttribut eCollection = new
Test.ArticleAtt ributeCollectio n();
Test.ArticleAtt ribute ArticleAttribut e = new Test.ArticleAtt ribute();

int i = 0;

while (i<2)
{
ArticleAttribut e.ArticleId = i;
ArticleAttribut e.Content = "Innhold " + i;
ArticleAttribut eCollection.Add (ArticleAttribu te);
i++;
}

Response.Write( ArticleAttribut eCollection.Cou nt);

this.dtgTest.Da taSource = ArticleAttribut eCollection;
this.dtgTest.Da taBind();
}
WHAT IS WRONG IN MY CODE???

May 18 '07 #2

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

Similar topics

2
2742
by: SammyBar | last post by:
Hi, I'm trying to bind a custom collection class to a data grid, following the guidelines from the article http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx. The problem is the article is in VisualBasic. I already get the collection to be recognized as a Data Source by the IDE. It populated the DataGrid correctly from the fields on the items object of the collection, but I can't get the DataGrid to...
7
4222
by: Pete Davis | last post by:
A different question this time. I have a DataGrid bound to a collection. Is there any way for me to allow sorting? The DataGrid.AllowSorting=true doesn't work, but that's probably because it can't assume the data types and thus can't sort them. I thought about implementing IComparable, but I don't see how that would work since it doesn't apply generically to all the fields/properties of the class. Thanks.
2
2091
by: Pete Nelson | last post by:
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...
8
2243
by: ASP Yaboh | last post by:
I have an ArrayList of data gathered from a database. I want to create a web page from this data by creating a <table>, each cell in each row displays the appropriate data. One of those cells in each row needs a <textarea> control. The background supporting classes are completed, the only task left now is to create the web page. I am at a loss on how to create the table in the page populated by the data. Previously, I would have just...
2
2200
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple properties, ProdID, Description, Quantity and UPC. 3 strings and a long. The LineItemsCollection class inherits from System.Collections.Specialized.NameObjectCollectionBase. It also implements both IEnumerable and IList.
1
1272
by: Luis Esteban Valencia | last post by:
Please everybody participate in this question. Hello my applicacion has many layers and classes and I think its well structured. PLease let me know if you disagree and why. 1. I have the user Interface (webforms) 2. I have a class Called Customer Class (it only has private fields, properties). Those properties connecto a Class called CustomerDALC (Customer Data Access Logic Component). this one must be the only responsible to access...
2
1478
by: trebor | last post by:
I bind a collection to a data grid, and it works okay, but when I try to create customized columns, it just doesn't work. Here is the code. Note that if I uncomment that section below, and use "DT" as the mapping name, it works fine. But I don't want to have to copy the collection to the data table every time. I searched Google and keep reading that you have to use "the classname of the collection," but nothing I use as a mapping name...
2
2044
by: Ivan Weiss | last post by:
Hi. This is a question I have posted before and have never figured out a working result. I have been recommended to read some books which I did which still have not answered my question. I am writing an application for my office for project management. I have several classes, one for an employee object, a vendor object, and a customer object. I want to make an employees, vendors, and customers object which will contain all or several...
6
1667
by: rodchar | last post by:
hey all, Dim _oItems As Outlook.Items Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) _oItems = oInbox.Items I can iterate thru this with a for-each loop however i cannot bind directly to datagrid. Any ideas why not? or how i can get this in a datagrid.
1
1485
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
8330
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,...
0
8850
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8523
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
8626
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
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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...
1
2749
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
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.