By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,367 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

Serializing drop-down list data sources in Session State

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Use DataTable or HashTable, they are serializable.

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:%2******************@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

Nov 18 '05 #2

P: n/a
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" <ki***@hotmail.com> wrote in message
news:O1**************@TK2MSFTNGP10.phx.gbl...
Use DataTable or HashTable, they are serializable.

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:%2******************@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


Nov 18 '05 #3

P: n/a
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" <ad*@taratuta.net> wrote in message
news:OA**************@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" <ki***@hotmail.com> wrote in message
news:O1**************@TK2MSFTNGP10.phx.gbl...
Use DataTable or HashTable, they are serializable.

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:%2******************@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



Nov 18 '05 #4

P: n/a
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" <ad*@taratuta.net> wrote in message
news:OA****************@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" <ki***@hotmail.com> wrote in message
news:O1**************@TK2MSFTNGP10.phx.gbl...
Use DataTable or HashTable, they are serializable.

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:%2******************@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
>
>



Nov 18 '05 #5

P: n/a
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" <ks******@takempis.com> wrote in message
news:uC*************@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" <ad*@taratuta.net> wrote in message
news:OA**************@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" <ki***@hotmail.com> wrote in message
news:O1**************@TK2MSFTNGP10.phx.gbl...
Use DataTable or HashTable, they are serializable.

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:%2******************@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
>
>



Nov 18 '05 #6

P: n/a
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" <ad*@taratuta.net> wrote in message
news:OE**************@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" <ks******@takempis.com> wrote in message
news:uC*************@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" <ad*@taratuta.net> wrote in message
news:OA**************@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" <ki***@hotmail.com> wrote in message
> news:O1**************@TK2MSFTNGP10.phx.gbl...
> > Use DataTable or HashTable, they are serializable.
> >
> > "Leszek Taratuta" <ad*@taratuta.net> wrote in message
> > news:%2******************@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
> > >
> > >
> >
> >
>
>



Nov 18 '05 #7

P: n/a
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" <ki***@hotmail.com> wrote in message
news:Ob**************@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" <ad*@taratuta.net> wrote in message
news:OE**************@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" <ks******@takempis.com> wrote in message
news:uC*************@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" <ad*@taratuta.net> wrote in message
news:OA**************@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" <ki***@hotmail.com> wrote in message
> news:O1**************@TK2MSFTNGP10.phx.gbl...
> > Use DataTable or HashTable, they are serializable.
> >
> > "Leszek Taratuta" <ad*@taratuta.net> wrote in message
> > news:%2******************@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
> > >
> > >
> >
> >
>
>



Nov 18 '05 #8

P: n/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" <ad*@taratuta.net> wrote in message
news:#A**************@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" <ki***@hotmail.com> wrote in message
news:Ob**************@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" <ad*@taratuta.net> wrote in message
news:OE**************@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" <ks******@takempis.com> wrote in message
news:uC*************@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" <ad*@taratuta.net> wrote in message
> news:OA**************@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" <ki***@hotmail.com> wrote in message
> > news:O1**************@TK2MSFTNGP10.phx.gbl...
> > > Use DataTable or HashTable, they are serializable.
> > >
> > > "Leszek Taratuta" <ad*@taratuta.net> wrote in message
> > > news:%2******************@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
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 18 '05 #9

P: n/a
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" <ks******@takempis.com> wrote in message
news:#r**************@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" <ad*@taratuta.net> wrote in message
news:#A**************@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" <ki***@hotmail.com> wrote in message
news:Ob**************@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" <ad*@taratuta.net> wrote in message
news:OE**************@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" <ks******@takempis.com> wrote in message
> news:uC*************@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" <ad*@taratuta.net> wrote in message
>> news:OA**************@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" <ki***@hotmail.com> wrote in message
>> > news:O1**************@TK2MSFTNGP10.phx.gbl...
>> > > Use DataTable or HashTable, they are serializable.
>> > >
>> > > "Leszek Taratuta" <ad*@taratuta.net> wrote in message
>> > > news:%2******************@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
>> > > >
>> > > >
>> > >
>> > >
>> >
>> >
>>
>>
>
>



Nov 18 '05 #10

P: n/a
Hi Leszek,

First of all, as was mentioned earlier, ListItems are UI elements. A
well-designed Data Layer should NEVER work with UI elements. Why, even your
business layer shouldn't be working with UI elements. Only data structures
should come from the Data Layer. That would be raw primitve data, such as
integers, dates, and strings, DataSets, DataTables, and DataReaders. Now,
there is some controversy over returning DataReaders, so the next smallest
data structure (other than primitives) would be a DataTable, and it really
has a relatively small footprint. DataReaders are the smallest, but have
some issues, such as necessitating a constant Connection while in use, as
well as being forward-only, read-only, and not being serializable.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:OI**************@TK2MSFTNGP11.phx.gbl...
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" <ks******@takempis.com> wrote in message
news:#r**************@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" <ad*@taratuta.net> wrote in message
news:#A**************@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" <ki***@hotmail.com> wrote in message
news:Ob**************@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" <ad*@taratuta.net> wrote in message
> news:OE**************@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" <ks******@takempis.com> wrote in message
> > news:uC*************@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" <ad*@taratuta.net> wrote in message
> >> news:OA**************@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" <ki***@hotmail.com> wrote in message
> >> > news:O1**************@TK2MSFTNGP10.phx.gbl...
> >> > > Use DataTable or HashTable, they are serializable.
> >> > >
> >> > > "Leszek Taratuta" <ad*@taratuta.net> wrote in message
> >> > > news:%2******************@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
> >> > > >
> >> > > >
> >> > >
> >> > >
> >> >
> >> >
> >>
> >>
> >
> >
>
>



Nov 18 '05 #11

P: n/a
Thanks a lot. It seems DataTable is the best solution.

In the meantime the database guy decided to fill ArrayLists not with
ListItems but with some user defined structures similar to ListItems:

public sealed class ItemData
{
public string name;
public int val;

public ItemData(string name, int val)
{
this.name = name;
this.val = val;
}
}

Now I need to populate drop-down lists manually using code like this:

// list - an ArrayList containing ItemDatas
// ddl - the drop-down list control
for ( int i = 0; i < list.Count; i++ )
{
ddl.Items.Add( new ListItem( ((ItemData) list[i]).Name, ((ItemData)
list[i]).Id.ToString() ) );
}

What do you think about such a solution? Is it any better than passing
DataTable? For sure it is more cumbersome in terms of populating the lists,
but the database guy wants the smallest possible footprint and ItemData
items are light (they are structures). But on the other hand they are
elements of ArrayList that boxes the sturcture elements (that are value
types) to have reference types.

So my question is which option is better DataTable or the custom-defined
ItemData elements contained in an ArrayList?

Thanks,
Leszek

"Kevin Spencer" <ks******@takempis.com> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
Hi Leszek,

First of all, as was mentioned earlier, ListItems are UI elements. A
well-designed Data Layer should NEVER work with UI elements. Why, even your business layer shouldn't be working with UI elements. Only data structures
should come from the Data Layer. That would be raw primitve data, such as
integers, dates, and strings, DataSets, DataTables, and DataReaders. Now,
there is some controversy over returning DataReaders, so the next smallest
data structure (other than primitives) would be a DataTable, and it really
has a relatively small footprint. DataReaders are the smallest, but have
some issues, such as necessitating a constant Connection while in use, as
well as being forward-only, read-only, and not being serializable.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:OI**************@TK2MSFTNGP11.phx.gbl...
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" <ks******@takempis.com> wrote in message
news:#r**************@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" <ad*@taratuta.net> wrote in message
news:#A**************@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" <ki***@hotmail.com> wrote in message
> news:Ob**************@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" <ad*@taratuta.net> wrote in message
> > news:OE**************@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" <ks******@takempis.com> wrote in message
> > > news:uC*************@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" <ad*@taratuta.net> wrote in message
> > >> news:OA**************@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" <ki***@hotmail.com> wrote in message
> > >> > news:O1**************@TK2MSFTNGP10.phx.gbl...
> > >> > > Use DataTable or HashTable, they are serializable.
> > >> > >
> > >> > > "Leszek Taratuta" <ad*@taratuta.net> wrote in message
> > >> > > news:%2******************@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
> > >> > > >
> > >> > > >
> > >> > >
> > >> > >
> > >> >
> > >> >
> > >>
> > >>
> > >
> > >
> >
> >
>
>



Nov 18 '05 #12

P: n/a
I would go with a DataTable.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:ux*************@TK2MSFTNGP12.phx.gbl...
Thanks a lot. It seems DataTable is the best solution.

In the meantime the database guy decided to fill ArrayLists not with
ListItems but with some user defined structures similar to ListItems:

public sealed class ItemData
{
public string name;
public int val;

public ItemData(string name, int val)
{
this.name = name;
this.val = val;
}
}

Now I need to populate drop-down lists manually using code like this:

// list - an ArrayList containing ItemDatas
// ddl - the drop-down list control
for ( int i = 0; i < list.Count; i++ )
{
ddl.Items.Add( new ListItem( ((ItemData) list[i]).Name, ((ItemData)
list[i]).Id.ToString() ) );
}

What do you think about such a solution? Is it any better than passing
DataTable? For sure it is more cumbersome in terms of populating the lists, but the database guy wants the smallest possible footprint and ItemData
items are light (they are structures). But on the other hand they are
elements of ArrayList that boxes the sturcture elements (that are value
types) to have reference types.

So my question is which option is better DataTable or the custom-defined
ItemData elements contained in an ArrayList?

Thanks,
Leszek

"Kevin Spencer" <ks******@takempis.com> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
Hi Leszek,

First of all, as was mentioned earlier, ListItems are UI elements. A
well-designed Data Layer should NEVER work with UI elements. Why, even your
business layer shouldn't be working with UI elements. Only data structures
should come from the Data Layer. That would be raw primitve data, such as integers, dates, and strings, DataSets, DataTables, and DataReaders. Now, there is some controversy over returning DataReaders, so the next smallest data structure (other than primitives) would be a DataTable, and it really has a relatively small footprint. DataReaders are the smallest, but have
some issues, such as necessitating a constant Connection while in use, as well as being forward-only, read-only, and not being serializable.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:OI**************@TK2MSFTNGP11.phx.gbl...
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" <ks******@takempis.com> wrote in message
news:#r**************@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" <ad*@taratuta.net> wrote in message
> news:#A**************@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" <ki***@hotmail.com> wrote in message
> > news:Ob**************@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" <ad*@taratuta.net> wrote in message
> > > news:OE**************@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" <ks******@takempis.com> wrote in message
> > > > news:uC*************@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" <ad*@taratuta.net> wrote in message
> > > >> news:OA**************@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" <ki***@hotmail.com> wrote in message
> > > >> > news:O1**************@TK2MSFTNGP10.phx.gbl...
> > > >> > > Use DataTable or HashTable, they are serializable.
> > > >> > >
> > > >> > > "Leszek Taratuta" <ad*@taratuta.net> wrote in message
> > > >> > > news:%2******************@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
> > > >> > > >
> > > >> > > >
> > > >> > >
> > > >> > >
> > > >> >
> > > >> >
> > > >>
> > > >>
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 18 '05 #13

P: n/a
Thanks a lot. I will use DataTables.

Leszek

"Kevin Spencer" <ks******@takempis.com> wrote in message
news:#9**************@TK2MSFTNGP09.phx.gbl...
I would go with a DataTable.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:ux*************@TK2MSFTNGP12.phx.gbl...
Thanks a lot. It seems DataTable is the best solution.

In the meantime the database guy decided to fill ArrayLists not with
ListItems but with some user defined structures similar to ListItems:

public sealed class ItemData
{
public string name;
public int val;

public ItemData(string name, int val)
{
this.name = name;
this.val = val;
}
}

Now I need to populate drop-down lists manually using code like this:

// list - an ArrayList containing ItemDatas
// ddl - the drop-down list control
for ( int i = 0; i < list.Count; i++ )
{
ddl.Items.Add( new ListItem( ((ItemData) list[i]).Name, ((ItemData)
list[i]).Id.ToString() ) );
}

What do you think about such a solution? Is it any better than passing
DataTable? For sure it is more cumbersome in terms of populating the lists,
but the database guy wants the smallest possible footprint and ItemData
items are light (they are structures). But on the other hand they are
elements of ArrayList that boxes the sturcture elements (that are value
types) to have reference types.

So my question is which option is better DataTable or the custom-defined
ItemData elements contained in an ArrayList?

Thanks,
Leszek

"Kevin Spencer" <ks******@takempis.com> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
Hi Leszek,

First of all, as was mentioned earlier, ListItems are UI elements. A
well-designed Data Layer should NEVER work with UI elements. Why, even

your
business layer shouldn't be working with UI elements. Only data structures should come from the Data Layer. That would be raw primitve data, such as integers, dates, and strings, DataSets, DataTables, and DataReaders. Now, there is some controversy over returning DataReaders, so the next smallest data structure (other than primitives) would be a DataTable, and it really has a relatively small footprint. DataReaders are the smallest, but have some issues, such as necessitating a constant Connection while in use, as well as being forward-only, read-only, and not being serializable.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Leszek Taratuta" <ad*@taratuta.net> wrote in message
news:OI**************@TK2MSFTNGP11.phx.gbl...
> 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" <ks******@takempis.com> wrote in message
> news:#r**************@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" <ad*@taratuta.net> wrote in message
> > news:#A**************@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" <ki***@hotmail.com> wrote in message
> > > news:Ob**************@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" <ad*@taratuta.net> wrote in message
> > > > news:OE**************@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" <ks******@takempis.com> wrote in message
> > > > > news:uC*************@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" <ad*@taratuta.net> wrote in message
> > > > >> news:OA**************@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" <ki***@hotmail.com> wrote in message
> > > > >> > news:O1**************@TK2MSFTNGP10.phx.gbl...
> > > > >> > > Use DataTable or HashTable, they are serializable.
> > > > >> > >
> > > > >> > > "Leszek Taratuta" <ad*@taratuta.net> wrote in message
> > > > >> > > news:%2******************@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
> > > > >> > > >
> > > > >> > > >
> > > > >> > >
> > > > >> > >
> > > > >> >
> > > > >> >
> > > > >>
> > > > >>
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 18 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.