How to get values in multiple checkbox?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lalamoves
    New Member
    • Jul 2018
    • 1

    How to get values in multiple checkbox?

    Can you please help me how to get the multiple values of checkbox.


    Code:
    @Html.Label("Revision of Records:")<br />
    @Html.CheckBox("Change Address", new { @class = "appType", @id = "ChangeAddress", @onclick = "clkChangeAddress()", @name = "nRevRecords" })  Change Address<br />
    @Html.CheckBox("Change Civil Status", new { @class = "appType", @id = "ChangeCivilStatus", @onclick = "clkChangeCivilStatus()", @name = "nRevRecords" }) Change Civil Status<br />
    @Html.CheckBox("Change Name", new { @class = "appType", @id = "ChangeName", @onclick = "clkChangeName()", @name = "nRevRecords" }) Change Name<br />
    @Html.CheckBox("Change Date of Birth", new { @class = "appType", @id = "ChangeDateBirth", @onclick = "clkChangeDateBirth()", @name = "nRevRecords" })  Change Date of Birth<br />
    @Html.CheckBox("Others", new { id = "ChkBoxOthers", @class = "appType", @onclick = "clkOthers()" })  Others <br />
  • techie700
    New Member
    • Nov 2018
    • 10

    #2
    I think, you should going to Implement CheckBoxList in ASP.Net MVC.
    visit this click here

    Comment

    • Sherin
      New Member
      • Jan 2020
      • 77

      #3
      Code:
      <%@ Page Language="C#" AutoEventWireup="true"%>    
            
      <!DOCTYPE html>
              
      <script runat="server">
          protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
          {
              var items = from ListItem li in CheckBoxList1.Items
                          where li.Selected == true
                          select li;
              
              Label1.Text = "you checked item(s).....<br />";
              
              foreach(ListItem li in items)
              {
                  Label1.Text += li.Text + " | " + li.Value + "<br />";
              }
          }
      </script>        
              
      <html>        
      <head id="Head1" runat="server">        
          <title>asp.net checkboxlist multiple selected values</title>
      </head>        
      <body>        
          <form id="form1" runat="server">        
          <div>        
              <h2 style="color:MidnightBlue; font-style:italic;">        
                  asp.net example - checkboxlist multiple selected values
              </h2>        
              <hr width="550" align="left" color="Gainsboro" />        
              <asp:Label       
                  ID="Label1"       
                  runat="server"      
                  Text="check item(s) from checkboxlist."
                  Font-Size="X-Large"
                  Width="350"
                  >      
              </asp:Label>      
              <br /><br />
              <asp:CheckBoxList 
                  ID="CheckBoxList1"
                  runat="server"
                  RepeatColumns="2"
                  AutoPostBack="true"
                  OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged"
                  >
                  <asp:ListItem Text="Rook" Value="1"></asp:ListItem>
                  <asp:ListItem Text="American Crow" Value="2"></asp:ListItem>
                  <asp:ListItem Text="White-necked Raven" Value="3"></asp:ListItem>
                  <asp:ListItem Text="Carrion Crow" Value="4"></asp:ListItem>
                  <asp:ListItem Text="Northern Raven" Value="5"></asp:ListItem>
              </asp:CheckBoxList>  
          </div>        
          </form>        
      </body>        
      </html>

      Comment

      Working...