473,581 Members | 2,786 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 1480
I got it, I was missing this:
ArticleAttribut e = new Test.ArticleAtt ribute(); // create a new
object
"Øyvind Isaksen" <ho***@egmont.n owrote in message
news:O2******** ******@TK2MSFTN GP04.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
2730
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...
7
4219
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...
2
2088
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. ...
8
2238
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...
1
1268
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...
2
1476
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...
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...
6
1665
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
1330
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...
0
7882
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7808
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...
0
8312
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6564
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...
1
5683
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...
0
5366
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...
0
3809
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...
1
2309
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
1
1410
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.