I have a list box in my page..
<td><%=Html.ListBox("listServiceTypes", Model.ServiceTypeListAll, new { style = "width: 500px;height:200px;" })%>
I need to disabled selecting multiple items from the list box? I am doing something like selecting one item and click delete button my page its delting one item from list box.. but If I select multple Items its throwing an error message/.?
Can any body help me out how to deactive or disable multiple items from list box
multiselect('disable'); will disable the selector (stored in the variable $widget ). And by replacing disable with enable you can enable it. So just run the function with the correct disable/enable setting and you can do it based on any condition.
You can take multiple selected text by iterating loop as mentioned below. $('#f1'). click(function(){ var rr = []; $('. selectpicker :selected').
You could do that with the following jQuery:
$(function(){
$("select[name='listServiceTypes']").removeAttr('multiple');
});
However, it would be much better to do it at the server side. Rather than using Html.ListBox
, it would be better to use Html.DropDownList
:
<%=Html.DropDownList("listServiceTypes",
Model.ServiceTypeListAll,
new { style = "width: 500px;height:200px", size=4 }); %>
This removes the need from having to do any jQuery/JavaScript to remove the multiple
attribute as it produces pretty much the same HTML but without the multiple
attribute. Having a value for size
that is greater than 1 tells the browser to display it as a multi-line list box.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With