listbox with checkboxes

2019-04-16 06:59发布

问题:

Greetings, in my asp.net mvc application I have a listbox rendered as follows:

<%= Html.ListBox("localization", (Model as SeekWeb.Models.CreateMessageViewModel).Localizations.AsEnumerable())%>

is there any way to have checkbox for each listbox item? if checkbox is checked then the appropriate listbox item is selected.

回答1:

I use a funky little jQuery plugin - jQuery Multiselect - to turn listboxes into more user friendly checkboxes. It's themeroller ready too!

Yeah, it does rely on the user having JS enabled but it does degrade gracefully to the standard listbox.

HTHs,
Charles



回答2:

Checkboxes aren't part of the standard listbox. If you need checkboxes you'll probably need to use a grid of some kind. MVCContrib has a grid control that's pretty good.