0

I am trying to make a DropDownList using divs and jquery (so that I can style it as I want)...and its working but the problem is I cant get the selected value from the list..

After selection of the option I am copying the selected value into the a div.. and I want to extract this using c# (in .aspx.cs page)... I've tried to do it using string builder and innerHtml(after adding runat="server" to the div).. but it doesn't work ...code is as follows

.aspx Page:

<div class="ddl">
    <div id="lowertriangle" class="lowertriangle"></div>
    <div id="uppertriangle" class="uppertriangle"></div>
    <div id="label" class="labeldiv_dd" runat="server"></div>//***This is the div from which I want to extract value***
    <div id="options" class="optionsidv_dd">
        <ul id="options_ul">
            <li id="0">Select One Option</li>
            <li id="1">Option 1</li>
            <li id="2">Option 2</li>
            <li id="3">Option 3</li>
            <li id="4">Option 4</li>
            <li id="5">Option 5</li>
        </ul>
    </div>
</div>

aspx.cs page

Method 1 that I tried:

string sel_text = label.InnerHtml;
display_sel_value.Text = sel_text.ToString(); 

2nd method:

var sb = new StringBuilder();
label.RenderControl(new HtmlTextWriter(new StringWriter(sb)));

string s = sb.ToString();

Kindly point out my mistakes and help me in this regard(in extracting innerHTML of the div that is). Thanks

nrsharma
  • 2,532
  • 3
  • 20
  • 36
Arawn
  • 17
  • 1
  • 3
  • 20
  • 1
    $( "#label" ).html(); – Ajinder Singh Oct 03 '13 at 12:35
  • What is the "a" div? You mean the label div? – Mark Graham Oct 03 '13 at 12:36
  • 1
    The problem is your not using a select. So there is nothing [POST](http://en.wikipedia.org/wiki/POST_(HTTP))ed to the server. Why are you trying to use a UL as a select? For style? – Liam Oct 03 '13 at 12:36
  • 1
    OK, so how exactly are you copying the text into the div? – Mr Lister Oct 03 '13 at 12:39
  • 1
    As @Liam pointed out, you need to send the data back to the server. You can do so either by having it in a form element (one example a hidden input) and submitting (posting) the form, or you can use client script requests (jQuery ajax calls) to send the data. – PHeiberg Oct 03 '13 at 12:40
  • @SpYk3HH, even if he uses jQuery how can he handle the selecting of the element. There is a fundamental flaw to this entire approach I feel. – Liam Oct 03 '13 at 12:45
  • Getting into an argument on the merits of ASP.Net doesn't answer this question. – Liam Oct 03 '13 at 12:46
  • @Liam if it were me, I'd right a short widget making my *ul menu* into a *ui-widget* menu with drop down, selection, and ajax posting all tied together in the widget call. Then I'd have one simple place to make adjustments as needed and probably only have the ajax post back a final *selection*, if that's really necessary, tho if we knew more about the project, I'm sure it's not. – SpYk3HH Oct 03 '13 at 12:48
  • [Why does ASP.NET webforms need the Runat=“Server” attribute?](http://stackoverflow.com/questions/304290/why-does-asp-net-webforms-need-the-runat-server-attribute) – SpYk3HH Oct 03 '13 at 12:50
  • The other issue here is the issue of "**selection**". I don't see anywhere in this code where `li` is being "*selected*". Via ASP or jQuery? Or even an `a` tag!? – SpYk3HH Oct 03 '13 at 12:54
  • `
  • Option 1
  • `..OR.. `
  • ` ..Backend.. `hyperLink.Text` – SpYk3HH Oct 03 '13 at 13:04
  • Solutions aside, I'm more and more convinced that this is the dreaded XY problem. The OP's _real_ issue is that they want to make the dropdown list look the way they want, and they believe it's impossible with a `` to look like? – Mr Lister Oct 03 '13 at 13:09
  • @SpYk3HH I didnt add the selection code cuz i didnt think it was necessary...its being done using jQuery – Arawn Oct 04 '13 at 10:08