i need to serialize my collection

I

Islamegy®

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(ArrayList));

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??
 
K

Kevin Spencer

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.
 
I

Islamegy®

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 said:
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® said:
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(ArrayList));

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??
 
K

Kevin Spencer

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® said:
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 said:
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® said:
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(ArrayList));

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??
 
K

Kevin Spencer

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/d...guide/html/cpconControlExecutionLifecycle.asp

--
HTH,

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

Islamegy® said:
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 said:
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® said:
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..
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.

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(ArrayList));

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??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top