0

Hi I am trying to add checkbox in my drop downlist. I googled it and I am getting example in asp.net as I am trying to do in MVC3. On my form edit User must be able to check values in the dropdown list. For example in below form for manufactures list currently it is just displaying values I must provide with a checkbox associated with that value.

My form:

 <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<EmsAdmin.Models.User>" %>
 <%@ Import Namespace="EmsAdmin.Models" %>

 <script type="text/javascript">
  //<![CDATA[
    // Focus on the first input box for the site
    $(document).ready(function () {
      $('#UserId').focus();
    });
  //]]>
</script>

<%= Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.") %>
<% using (Html.BeginForm()) {%>
  <%= Html.AntiForgeryToken() %>
  <p>
    <%= Html.LabelFor(e=>e.Id,"Id:") %>
    <%: Model.Id %>
  </p>
  <p>
    <%= Html.LabelFor(e=>e.PersonId,"Person:") %>
    <%= Html.DropDownListFor(e => e.PersonId, (SelectList)ViewData["allPersons"], "Select a person", new { @style = "width: 255px;" })%>
    <%= Html.ValidationMessageFor(e=>e.Person,"") %>
  </p>
  <p>
    <%= Html.LabelFor(e=>e.Email,"Email:") %>
    <%= Html.TextBoxFor(e => e.Email, new { @style = "width:250px;" })%>
    <%= Html.ValidationMessageFor(e=>e.Email,"") %>
  </p>
    <%= Html.LabelFor(e=>e.Approve,"Aprrove User:") %>
    <%= Html.CheckBoxFor(e=> e.Approve,Model.Approve) %><span>&nbsp;Switch this on if you want to add regitrar </span>
    <%= Html.ValidationMessageFor(e=>e.Approve,"") %>
  </p>
  <p>
    <%= Html.LabelFor(e=>e.ManufacturerDescription,"Brand:") %>
    <%= Html.DropDownListFor(e => e.ManufacturerDescription, (SelectList)ViewData["allManufacturers"], "Select  Brands", new { @style = "width: 255px;" })%>
    <%= Html.ValidationMessageFor(e=>e.ManufacturerDescription,"") %>
  </p>
  <p>
    <%= Html.LabelFor(e=>e.CountryName,"Country:") %>
    <%= Html.DropDownListFor(e => e.CountryName, (SelectList)ViewData["allCountries"], "Select Countries", new { @style = "width: 255px;" })%>
    <%= Html.ValidationMessageFor(e=>e.CountryName,"") %>
  </p>
  <p>
    <%= Html.LabelFor(e=>e.Role,"Role:") %>
    <%= Html.DropDownListFor(e => e.Role, (SelectList)ViewData["allRoles"], "Select Roles", new { @style = "width: 255px;" })%>
    <%= Html.ValidationMessageFor(e=>e.Role,"") %>
  </p>
  <p>
    <input type="submit" value="Save" />
    <%= Html.ActionLink("Cancel","Details",new {id=Model.Id},new {@title="exit without saving"}) %>
  </p>
<% } %>
3
  • 1
    Please add comment and do down vote. Thanks Commented Jul 30, 2013 at 12:50
  • 1
    fyi, you're missing a <p> above your Approve User: (noticed while I reformatted) Commented Jul 30, 2013 at 12:54
  • @BradChristie Thankyou I will update it. Commented Jul 30, 2013 at 12:57

1 Answer 1

2

There is no base html input such as dropdown with checkboxes. You can use side-part control libraries like DevExpress or make your own control.

Look here for jquery plugin which override base markup.

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

Comments

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.