c# - DropDownList with anchor tag elements -


i new .net programming , perhaps trying relatively simple couldn't find useful example until now.

i want generate anchor elements dropdownlist. have following code in asp.net:

<asp:dropdownlist id="dropdownlist1" runat="server" autopostback="true"> </asp:dropdownlist> 

in code behind(c#), want interrogate database (the result returns url, description , title) , fill in dropdownlist following:

<a href="url">title description</a> 

i add db results dropdownlist this:

while (reader){     list.add("<a href='" + url + "'> " + title +" "+  description+"</a>"); } this.dropdownlist1.datasource = list;  this.dropdownlist1.databind(); 

but showing whole line dropdownlist:

"<a href='" + url + "'> " + title +" "+  description+"</a>" 

,where url, title , description interpreted, , anchor tag appearing well.

i want display only: title description. , on selected, want redirect user url indicated in href attribute.

is possible in asp.net , c#? can me example or tips?

i think, instead of trying bring anchor tags in dropdown, should show normal select element url value of option. html markup this

<select id="someselect">   <option value="http://www.google.com">google</option>   <option value="http://www.aol.com">aol</option>   <option value="http://www.yahoo.com">yahoo</option> </select> 

now use javascript listen change event of dropdown , selected item's value attribute's value , use navigate. below code sample assuming have jquery library loaded page.

$(function(){    $("#someselect").change(function(e){      var selectedurl=$(this).val();      window.location.href=selectedurl;   });  }); 

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -