473,385 Members | 1,693 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,385 software developers and data experts.

i need to serialize my collection

In my EntityCollection inherted from CollectionBase I marked it
[Serializable] and Implement ISerializable Interface..
here is the code..
GetObjectDate( .....)
info.AddValue("Col",this.InnerList,typeof(ArrayLis t));

and while the InnerList is read only so i found some codes to workaround
using reflection.. but i didn't work so i tried to Add it using this in the
protected Constractor
{
ArrayList arr = (ArrayList)info.GetValue("Col",typeof(ArrayList));
this.InsertRange(arr);
}
the Add methodd which is needed for serialization is also there...
List.Add(entity)

but When i add this to my page viewstate and retive it back using this code
in Page_Load
{
if(!IsPostBack)
ent = new EntityCollection();
ent.Add(Entity.CreateInstance("ID1",Name));
ent.Add(Entity.CreateInstance("ID2",Name));
ent.Add(Entity.CreateInstance("ID3",Name));
Datagrid1.DataSource = ent;
Datagrid1.Databind();
ViewState.Add("coll",ent);
}
till this point there is No problems i get my collection displayed in the
grid

when i add or delete any item
{
ent = (EntityCollection)ViewState["coll"];
ent.Add(Entity.CreateInstance("ID3",Name));
Datagrid1.Databind();
}
my collection disapear even it i removed the if(!IsPostBack) or moved it to
Page_Init i will find only the original records not the one i added later so
what am i miss here??


Nov 19 '05 #1
4 1464
Well, forst of all if the DataGrid is ViewState enabled, there is no need to
add the Collection it is bound to to ViewState. The DataGrid contents are
saved in ViewState already.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Islamegy®" <Is******@Private.4me> wrote in message
news:OX**************@TK2MSFTNGP14.phx.gbl...
In my EntityCollection inherted from CollectionBase I marked it
[Serializable] and Implement ISerializable Interface..
here is the code..
GetObjectDate( .....)
info.AddValue("Col",this.InnerList,typeof(ArrayLis t));

and while the InnerList is read only so i found some codes to workaround
using reflection.. but i didn't work so i tried to Add it using this in
the protected Constractor
{
ArrayList arr = (ArrayList)info.GetValue("Col",typeof(ArrayList));
this.InsertRange(arr);
}
the Add methodd which is needed for serialization is also there...
List.Add(entity)

but When i add this to my page viewstate and retive it back using this
code
in Page_Load
{
if(!IsPostBack)
ent = new EntityCollection();
ent.Add(Entity.CreateInstance("ID1",Name));
ent.Add(Entity.CreateInstance("ID2",Name));
ent.Add(Entity.CreateInstance("ID3",Name));
Datagrid1.DataSource = ent;
Datagrid1.Databind();
ViewState.Add("coll",ent);
}
till this point there is No problems i get my collection displayed in the
grid

when i add or delete any item
{
ent = (EntityCollection)ViewState["coll"];
ent.Add(Entity.CreateInstance("ID3",Name));
Datagrid1.Databind();
}
my collection disapear even it i removed the if(!IsPostBack) or moved it
to Page_Init i will find only the original records not the one i added
later so what am i miss here??

Nov 19 '05 #2
My Datagrid is Viwstate enabled and if the selection changeed i have no
problems and collection is there but when i add or remove from the
collection i loose it..
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
Well, forst of all if the DataGrid is ViewState enabled, there is no need
to add the Collection it is bound to to ViewState. The DataGrid contents
are saved in ViewState already.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.

"Islamegy®" <Is******@Private.4me> wrote in message
news:OX**************@TK2MSFTNGP14.phx.gbl...
In my EntityCollection inherted from CollectionBase I marked it
[Serializable] and Implement ISerializable Interface..
here is the code..
GetObjectDate( .....)
info.AddValue("Col",this.InnerList,typeof(ArrayLis t));

and while the InnerList is read only so i found some codes to workaround
using reflection.. but i didn't work so i tried to Add it using this in
the protected Constractor
{
ArrayList arr = (ArrayList)info.GetValue("Col",typeof(ArrayList));
this.InsertRange(arr);
}
the Add methodd which is needed for serialization is also there...
List.Add(entity)

but When i add this to my page viewstate and retive it back using this
code
in Page_Load
{
if(!IsPostBack)
ent = new EntityCollection();
ent.Add(Entity.CreateInstance("ID1",Name));
ent.Add(Entity.CreateInstance("ID2",Name));
ent.Add(Entity.CreateInstance("ID3",Name));
Datagrid1.DataSource = ent;
Datagrid1.Databind();
ViewState.Add("coll",ent);
}
till this point there is No problems i get my collection displayed in the
grid

when i add or delete any item
{
ent = (EntityCollection)ViewState["coll"];
ent.Add(Entity.CreateInstance("ID3",Name));
Datagrid1.Databind();
}
my collection disapear even it i removed the if(!IsPostBack) or moved it
to Page_Init i will find only the original records not the one i added
later so what am i miss here??


Nov 19 '05 #3
In that case, you shouldn't need to DataBind again. It is already bound to
the DataGrid.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Islamegy®" <Is******@Private.4me> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
My Datagrid is Viwstate enabled and if the selection changeed i have no
problems and collection is there but when i add or remove from the
collection i loose it..
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
Well, forst of all if the DataGrid is ViewState enabled, there is no need
to add the Collection it is bound to to ViewState. The DataGrid contents
are saved in ViewState already.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.

"Islamegy®" <Is******@Private.4me> wrote in message
news:OX**************@TK2MSFTNGP14.phx.gbl...
In my EntityCollection inherted from CollectionBase I marked it
[Serializable] and Implement ISerializable Interface..
here is the code..
GetObjectDate( .....)
info.AddValue("Col",this.InnerList,typeof(ArrayLis t));

and while the InnerList is read only so i found some codes to
workaround using reflection.. but i didn't work so i tried to Add it
using this in the protected Constractor
{
ArrayList arr = (ArrayList)info.GetValue("Col",typeof(ArrayList));
this.InsertRange(arr);
}
the Add methodd which is needed for serialization is also there...
List.Add(entity)

but When i add this to my page viewstate and retive it back using this
code
in Page_Load
{
if(!IsPostBack)
ent = new EntityCollection();
ent.Add(Entity.CreateInstance("ID1",Name));
ent.Add(Entity.CreateInstance("ID2",Name));
ent.Add(Entity.CreateInstance("ID3",Name));
Datagrid1.DataSource = ent;
Datagrid1.Databind();
ViewState.Add("coll",ent);
}
till this point there is No problems i get my collection displayed in
the grid

when i add or delete any item
{
ent = (EntityCollection)ViewState["coll"];
ent.Add(Entity.CreateInstance("ID3",Name));
Datagrid1.Databind();
}
my collection disapear even it i removed the if(!IsPostBack) or moved it
to Page_Init i will find only the original records not the one i added
later so what am i miss here??



Nov 19 '05 #4
I hope yuo'll forgive me, but I don't have time to look thorough all that
code.

This sort of problem is usually associated with a sequence issue. ASP.Net
Controls, including, and perhaps most importantly, System.Web.UI.Page, have
a sequence of execution. Certain events fire in a certain sequence, and it's
important to make sure that you put your code in the right place in the
sequence, that is, in the right event handler. The following is a link to an
MSDN .Net Libary article that explains the "Execution Lifecycle" of ASP.Net
Controls. I keep a copy taped to my office wall!

http://msdn.microsoft.com/library/de...nLifecycle.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Islamegy®" <Is******@Private.4me> wrote in message
news:uY**************@TK2MSFTNGP12.phx.gbl...
Ok.. that's dosn't make diffrent.. In this way the data is there in the
grid but When i add new entity i don't find it??
Do u tell me what's wrong i do??
I attached my files so u code tell me what's wrong i do, Why i can't add
new entity??

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:ed**************@TK2MSFTNGP10.phx.gbl...
In that case, you shouldn't need to DataBind again. It is already bound
to
the DataGrid.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.

"Islamegy®" <Is******@Private.4me> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
My Datagrid is Viwstate enabled and if the selection changeed i have no
problems and collection is there but when i add or remove from the
collection i loose it..
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
Well, forst of all if the DataGrid is ViewState enabled, there is no
need
to add the Collection it is bound to to ViewState. The DataGrid
contents
are saved in ViewState already.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.

"Islamegy®" <Is******@Private.4me> wrote in message
news:OX**************@TK2MSFTNGP14.phx.gbl...
> In my EntityCollection inherted from CollectionBase I marked it
> [Serializable] and Implement ISerializable Interface..
> here is the code..
> GetObjectDate( .....)
> info.AddValue("Col",this.InnerList,typeof(ArrayLis t));
>
> and while the InnerList is read only so i found some codes to
> workaround using reflection.. but i didn't work so i tried to Add it
> using this in the protected Constractor
> {
> ArrayList arr = (ArrayList)info.GetValue("Col",typeof(ArrayList));
> this.InsertRange(arr);
> }
> the Add methodd which is needed for serialization is also there...
> List.Add(entity)
>
> but When i add this to my page viewstate and retive it back using this
> code
> in Page_Load
> {
> if(!IsPostBack)
> ent = new EntityCollection();
> ent.Add(Entity.CreateInstance("ID1",Name));
> ent.Add(Entity.CreateInstance("ID2",Name));
> ent.Add(Entity.CreateInstance("ID3",Name));
> Datagrid1.DataSource = ent;
> Datagrid1.Databind();
> ViewState.Add("coll",ent);
> }
> till this point there is No problems i get my collection displayed in
> the grid
>
> when i add or delete any item
> {
> ent = (EntityCollection)ViewState["coll"];
> ent.Add(Entity.CreateInstance("ID3",Name));
> Datagrid1.Databind();
> }
> my collection disapear even it i removed the if(!IsPostBack) or moved
> it
> to Page_Init i will find only the original records not the one i added
> later so what am i miss here??
>
>
>
>



Nov 19 '05 #5

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

Similar topics

7
by: Lars-Erik Aabech | last post by:
Hi! I've got problems with serializing my collections of business objects. The objects themselves serialize fine, but the collections fail. I've got the following structure: Base collection...
14
by: vince | last post by:
Can I add (append) to an xml file that already contains a serialized object, and be able to deserialize to either or both objects from the same file...??? How is this done...?? thanks, vince
2
by: films | last post by:
I understand the concept. Serialization of a class will add all the sub-objects of the class to the stream if there are also serializible. So say I have: class Author {
3
by: Gislain | last post by:
Hello, I'm looking for a best way to serialize multiple / different object in the same XML file, and of course, how can i deserialize it. Actualy, when i serialize the first object in XML...
2
by: Jinsong Liu | last post by:
I have following 3 classes public class MyMainClass { MyCollection<MyObject> m_oMyObjectCollection = null; private string m_sID = string.Empty; public MyCollection<MyObject> Collection {
4
by: Joe | last post by:
If I create a simple collection with say 20 columns and 5000 row and a DataTable with the same and serialize both, the DataTable file is at least 2 times the size as the simple collection. What is...
7
by: Sugandh Jain | last post by:
I am using a method to serialize objects to xml. this method is working fine to serialize most of the objects to Xml. For one collection object, it is not doing so. The Collection and its...
0
by: Dmitry Nogin | last post by:
Hi, Is it possible to xml-serialize an heterogenous collection? I mean the situation when class B inherits class A, and I'd like to serialize (to application settings) my...
2
by: =?Utf-8?B?U2hhd24=?= | last post by:
Hi; I would like to be able to use the XMLSerializer to serialize and deserialize a dictionary. is that possible? i know that you can serialize an object that implements the ICollection interface....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.