Thursday, March 22, 2012

Serializing drop-down list data sources in Session State

Hello,
I have several drop-down lists on my ASP.NET page. I need to keep data
sources of these lists in Session State.
What would be the most effective method to serialize this kind of data
structures?
Thanks for any hints,
Leszek TaratutaUse DataTable or HashTable, they are serializable.
"Leszek Taratuta" <ads@.taratuta.net> wrote in message
news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
> Hello,
> I have several drop-down lists on my ASP.NET page. I need to keep data
> sources of these lists in Session State.
> What would be the most effective method to serialize this kind of data
> structures?
> Thanks for any hints,
> Leszek Taratuta
>
Thanks, but this what I have already tried. The problem is the ListItem
class is not serializable.
I have created my own ListItem-like class (serializable) and copied
drop-down list data sources (using my ListItem class) to ArrayLists. Then I
put the array lists into a hash table with keys as drop-down lists' ids.
This solution does not work. When I try to deserialize such a structure,
.NET gives me an exception that the type version has been changed and it is
not possible to deserialize data. I think the type is too complex for
serialization (custom ListItem-like objects within ArrayLists within a
Hashtable).
Any other suggestions,
Leszek
"Kikoz" <kikoz@.hotmail.com> wrote in message
news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> Use DataTable or HashTable, they are serializable.
> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
>
You didn't say you wanted to serialize Controls, you said you wanted to
serialize the DataSource that you're binding to. A ListItem is a UI Control,
and there's no need (or even a good reason) to serialize it. Just store the
DataTable in Session and bind to it.
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
"Leszek Taratuta" <ads@.taratuta.net> wrote in message
news:OAlaM5#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> Thanks, but this what I have already tried. The problem is the ListItem
> class is not serializable.
> I have created my own ListItem-like class (serializable) and copied
> drop-down list data sources (using my ListItem class) to ArrayLists. Then
I
> put the array lists into a hash table with keys as drop-down lists' ids.
> This solution does not work. When I try to deserialize such a structure,
> .NET gives me an exception that the type version has been changed and it
is
> not possible to deserialize data. I think the type is too complex for
> serialization (custom ListItem-like objects within ArrayLists within a
> Hashtable).
> Any other suggestions,
> Leszek
> "Kikoz" <kikoz@.hotmail.com> wrote in message
> news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
>
Live sample:
(If this ddl doesn't depend on specific user, store it in Application or
Cache):
const string SOURCE_NAME = "SourceName";
private DataTable GetThatFreakingSource()
{
if(Application[SOURCE_NAME] == null)
{
DataTable tbl = GetThatTableFromDbOrSomething();
Application[SOURCE_NAME] = tbl;
return tbl;
}
return (DataTable)Application[SOURCE_NAME];
}
private void BindThatDdl()
{
ddl.DataSource = GetThatFreakingSource();
ddl.DataBind();
}
Done. In sort, when you box Application[SOURCE_NAME] to DataTable (last line
in the first method) that's where serilization takes place. Automatically.
Enjoy :)
"Leszek Taratuta" <ads@.taratuta.net> wrote in message
news:OAlaM5%23yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> Thanks, but this what I have already tried. The problem is the ListItem
> class is not serializable.
> I have created my own ListItem-like class (serializable) and copied
> drop-down list data sources (using my ListItem class) to ArrayLists. Then
> I
> put the array lists into a hash table with keys as drop-down lists' ids.
> This solution does not work. When I try to deserialize such a structure,
> .NET gives me an exception that the type version has been changed and it
> is
> not possible to deserialize data. I think the type is too complex for
> serialization (custom ListItem-like objects within ArrayLists within a
> Hashtable).
> Any other suggestions,
> Leszek
> "Kikoz" <kikoz@.hotmail.com> wrote in message
> news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
>
Thanks. I forgot the ListItems are controls.
The situation is that my data sources are not DataTables. I have ArrayLists
filled with ListItems.
The problem is I cannot serialize this kind of ArrayLists to session state
kept in state server.
Thanks,
Leszek
"Kevin Spencer" <kspencer@.takempis.com> wrote in message
news:uC0bhX$yEHA.336@.TK2MSFTNGP10.phx.gbl...
> You didn't say you wanted to serialize Controls, you said you wanted to
> serialize the DataSource that you're binding to. A ListItem is a UI
Control,
> and there's no need (or even a good reason) to serialize it. Just store
the
> DataTable in Session and bind to it.
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Neither a follower
> nor a lender be.
> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> news:OAlaM5#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
Then
> I
> is
data
data
>
I think you complicate things for no obvious reason :) I may be totally
wrong, it all depends on particular situation, but this is what it seems
like. Much easier to store data in serializable object like DataTable and
then keep it on server, even if that would require to put your data in such
table first.
"Leszek Taratuta" <ads@.taratuta.net> wrote in message
news:OEVLPz$yEHA.1412@.tk2msftngp13.phx.gbl...
> Thanks. I forgot the ListItems are controls.
> The situation is that my data sources are not DataTables. I have
> ArrayLists
> filled with ListItems.
> The problem is I cannot serialize this kind of ArrayLists to session state
> kept in state server.
> Thanks,
> Leszek
> "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> news:uC0bhX$yEHA.336@.TK2MSFTNGP10.phx.gbl...
> Control,
> the
> Then
> data
> data
>
Well, I know it is much easier to store data in serializable object like
DataTable but I work in a team, and what I receive from the data layer is
ArrayList containing ListItems.
For now the only resonable solution is to convert the ArrayLists to
DataTables. It is not efficient though. I thought it would be any other more
appropriate way to store this kind of data. Any kind of serialization from
ArrayLists to strings or so, and then deserialization.
Thanks,
Leszek
"Kikoz" <kikoz@.hotmail.com> wrote in message
news:Obu#I3$yEHA.1292@.TK2MSFTNGP10.phx.gbl...
> I think you complicate things for no obvious reason :) I may be totally
> wrong, it all depends on particular situation, but this is what it seems
> like. Much easier to store data in serializable object like DataTable and
> then keep it on server, even if that would require to put your data in
such
> table first.
>
> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> news:OEVLPz$yEHA.1412@.tk2msftngp13.phx.gbl...
state
ListItem
a
>
Well, Leszek, it seems that the wrong person is asking this question of the
newsgroup. Whoever is sending you ArrayLists of ListItems is the one who
needs the help!
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
"Leszek Taratuta" <ads@.taratuta.net> wrote in message
news:#AIc3TAzEHA.1292@.TK2MSFTNGP10.phx.gbl...
> Well, I know it is much easier to store data in serializable object like
> DataTable but I work in a team, and what I receive from the data layer is
> ArrayList containing ListItems.
> For now the only resonable solution is to convert the ArrayLists to
> DataTables. It is not efficient though. I thought it would be any other
more
> appropriate way to store this kind of data. Any kind of serialization from
> ArrayLists to strings or so, and then deserialization.
> Thanks,
> Leszek
> "Kikoz" <kikoz@.hotmail.com> wrote in message
> news:Obu#I3$yEHA.1292@.TK2MSFTNGP10.phx.gbl...
and
> such
> state
to
store
> ListItem
ArrayLists.
and
for
within
> a
keep
of
>
Thank you. I am going to talk with the guy who creates the data layer.
BTW
What could be the best alternative to get drop-down list data sources from
the data layer? DataTables are pretty heavy. Any other possibilities.
Thanks,
Leszek
"Kevin Spencer" <kspencer@.takempis.com> wrote in message
news:#raiusAzEHA.1452@.TK2MSFTNGP11.phx.gbl...
> Well, Leszek, it seems that the wrong person is asking this question of
the
> newsgroup. Whoever is sending you ArrayLists of ListItems is the one who
> needs the help!
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Neither a follower
> nor a lender be.
> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> news:#AIc3TAzEHA.1292@.TK2MSFTNGP10.phx.gbl...
is
> more
from
totally
seems
> and
wanted
> to
> store
copied
> ArrayLists.
lists'
> and
> for
> within
> keep
kind
> of
>

0 comments:

Post a Comment