user1534664
user1534664

Reputation: 3418

How to hide a value for each item in a <asp:dropdownlist>

I have an <asp:DropDownList> element filled with items, where each item represents an application name. I would like to pass a hidden value (the url of the application be specific) for each of these items. I need the value in my Javascript code. I think my code would look better if I prevent the operation of having to query the database using an ajax call.

Is it possible to hide multiple values for each item in a dropdownlist? If so, how?

Upvotes: 0

Views: 218

Answers (1)

jlee-tessik
jlee-tessik

Reputation: 1520

In codebehind:

  1. Use the Newtonsoft.Json library to convert data into a JSON object https://dotnetfiddle.net/tMXHsI

  2. Set an <asp:HiddenField> value with that content.

On the page, in javascript:

  1. Parse the hidden field's value var myURLs = JSON.parse( HiddenField.value );

You now have a javascript object that you can pull data from.

Upvotes: 1

Related Questions