Accessing data from option list in ASP
Hi,
I got a query where I want to access all the items of a list (select tag) in asp.
How I can perform this task
please suggest
regards
Abhijeet Nigam
Web Development
Hi,
I got a query where I want to access all the items of a list (select tag) in asp.
How I can perform this task
please suggest
regards
Abhijeet Nigam
by abhijeet_askn Accepted solution
by hercules.gunter Accepted solution
Since you say "in ASP", I presume you want to do this server-side. The Request object contains only the selected key value (or values, comma-separated, if multiple-select is enabled). The remaining contents of the list are unknowable from the Request object. However, you presumably built the list server-side, so whatever the source of that list was when you built it should be accessible to you.
You could add a Javascript routine to return a hidden variable containing all the keys in the dropdown, or you could build the hidden variable server-side. This still amounts to the fact that the server-side code which built the list should be accessible to you.
If that's no help, I'm afraid I don't understand the question.
by abhijeet_askn Accepted solution
I created the list at client side and adding data to it. I want all that data at server side. I read that list.options carry the array of list items. but I am not able to access it
Please suggest
by hercules.gunter Accepted solution
I would go for a hidden variable which is updated to include the additions to the list. Probably it would be simplest to generate it when submitting the page, i.e. trap the submit() event and then pack the hidden field.
The simplest form I can think of is to pack a field with two delimiters, which obviously mustn't be in any of the keys or values you use. Assuming that : and ; qualify, you would iterate through the values in the select object, and construct a string with "key1:value1;key2:value2;..." and so on. Read that hidden variable, and split it to get the client-side list.
Further thought: have two hidden variables, one for keys and one for values. That way a you can get matching arrays by splitting the two strings. The first suggestion means splitting to get an array of key/value pairs, and each element of this array must be split to get a single key and value. The two-list approach means two splits only, so would be a little more efficient.
This discussion is closed to new replies.
Sort by Trending