2

Looked and found solutions with broken links or that did not work for me, that said I am using the multiselect found here http://abeautifulsite.net/blog/2008/04/jquery-multiselect/ I need to get the selected checkboxes when I hit a button to use them in c#, I am totally stuck on this one and the example used in the demo that does it is in php :-(

JQuery:

  $(document).ready(function () {
        $("#EGM").multiSelect({ selectAll: false, oneOrMoreSelected: '*' });
    });

Control:

 <select id="EGM" multiple="multiple" style="width: 100px;">
        <optgroup label="EGM">
         <option>data</option>           
        <option>driven</option>           
        <option>dropdown</option>      
        </optgroup>
        <optgroup  label="System Type">SystemType
         <option>data</option>          
         <option>driven</option>           
         <option>dropdown</option>          
         </optgroup>            
         </select>

Where I need my selected values in the code behind:

  protected void SubmitButton_Click(object sender, EventArgs e)
{

     //what goes here?!?

}
3
  • You said 'control'. Is that HTML the HTML the control generated or have you manually written it? Commented Sep 28, 2011 at 2:05
  • there is another thread with the same question stackoverflow.com/questions/2700010/… Commented Sep 28, 2011 at 2:17
  • @AgamandTheTrue, as I mentioned, I have checked for this here, if you go to your link and see the selected answer you can see the provided link there is broken as mentioned in the 1st sentence of my question. I really do try to find before I post. Commented Sep 28, 2011 at 3:21

1 Answer 1

2

The proper way to do this would be to change <select ...> to <asp:ListBox ...> and update your script to

$(document).ready(function() {
    $('#<%=this.EGM.ClientID%>').multiSelect(...);
});

But the <asp:ListBox> control doesn't natively support optgroup inner elements. There are workarounds using ControlAdapters (see: Dropdownlist control with <optgroup>s for asp.net (webforms)? - VB.NET). Using this, you can access the ListItems directly.

That said, a less proper yet less time consuming way, you could also just dump $('#EGM').val() into an <asp:HiddenField> by specifying a callback method in the multiSelect initializer and enumerate the array in the code behind.

Sign up to request clarification or add additional context in comments.

3 Comments

The opt group is not needed, I would be willing to split it into two. I will try this tomorrow and if it works I will mark this as accepted. Thanks!
no dice on this :-( I guess the multiselect only works on the select element.
I literally 5 minutes ago just dumped it into a hidden field, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.