i m new in asp.net..
asp.net CheckBoxList control does not have the
CheckBoxList.CheckedItems.Count like the one in the windows Application.
i am manually converting a windows app to asp.net ,
i need to use the functionally of that Method .. any help please

i m new in asp.net..
asp.net CheckBoxList control does not have the
CheckBoxList.CheckedItems.Count like the one in the windows Application.
i am manually converting a windows app to asp.net ,
i need to use the functionally of that Method .. any help please

Check out these prop, and wrap it in loop

CheckBoxList.Items.Count
if CheckBoxList.checked = true then
   'do ur stuff
end if

Mark as solved if it helps you!!!

Add CheckBoxList markup into .aspx

<form id="form1" runat="server">
         <asp:CheckBoxList ID="CheckBoxList1" runat="server">
            <asp:ListItem>Item1</asp:ListItem>
            <asp:ListItem>Item2</asp:ListItem>
            <asp:ListItem>Item3</asp:ListItem>
        </asp:CheckBoxList>
         <asp:Button ID="Button1" runat="server" Text="Button" />
    </form>

and in code-behind (.cs), handle the Click event

protected void Button1_Click(object sender, EventArgs e)
        {
           foreach (ListItem item in CheckBoxList1.Items)
                if (item.Selected)
                    Response.Write("<br/>" + item.Text);

        }

Hi

Check below code it will help you.

<%@ Page language="c#" src="CheckBoxTest.aspx.cs" AutoEventWireup="false" Inherits="CheckBoxTest" %>
<HTML>
  <body>
    <form id="Form1" method="post" runat="server">
      Choose your favourite programming languages:<br>
      <br>
      <asp:CheckBoxList id="chklst" runat="server" /><br>
      <br>
      <asp:Button id="cmdOK" Text="OK" runat="server" /><br>
      <br>
      <asp:Label id="lblResult" runat="server" />
    </form>
  </body>
</HTML>
 

<%--

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

  public class CheckBoxTest : System.Web.UI.Page
  {
    protected System.Web.UI.WebControls.CheckBoxList chklst;
    protected System.Web.UI.WebControls.Button cmdOK;
    protected System.Web.UI.WebControls.Label lblResult;
  
    private void Page_Load(object sender, System.EventArgs e)
    {
      if (this.IsPostBack == false)
      {
        chklst.Items.Add("C");
        chklst.Items.Add("C++");
        chklst.Items.Add("C#");
        chklst.Items.Add("Visual Basic 6.0");
        chklst.Items.Add("VB.NET");
        chklst.Items.Add("Pascal");
      }
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
      InitializeComponent();
      base.OnInit(e);
    }
    
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
      this.cmdOK.Click += new System.EventHandler(this.cmdOK_Click);
      this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    private void cmdOK_Click(object sender, System.EventArgs e)
    {
      lblResult.Text = "You chose:<b>";

      foreach (ListItem lstItem in chklst.Items)
      {
        if (lstItem.Selected == true)
        {
          // Add text to label.
          lblResult.Text += "<br>" + lstItem.Text;
        }
      }

      lblResult.Text += "</b>";
    }
  }


--%>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.