Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. checkboxs problem

checkboxs problem

Scheduled Pinned Locked Moved ASP.NET
help
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    test 09
    wrote on last edited by
    #1

    this is code i wrote to check check boxes in datalist control but if i checked all checkboxes only it is returning true not for one or multiple checkboxes help me...:confused:

    foreach (DataListItem dli in DataList1.Items)
    {
    CheckBox Chk = (CheckBox)dli.FindControl("CheckBox1");
    if (Chk.Checked)
    {
    str13 = "cheked";
    }
    else
    {
    str13 = "you need to check";
    }
    }
    LblErr.Visible = true;
    LblErr.Text = str13;

    A 1 Reply Last reply
    0
    • T test 09

      this is code i wrote to check check boxes in datalist control but if i checked all checkboxes only it is returning true not for one or multiple checkboxes help me...:confused:

      foreach (DataListItem dli in DataList1.Items)
      {
      CheckBox Chk = (CheckBox)dli.FindControl("CheckBox1");
      if (Chk.Checked)
      {
      str13 = "cheked";
      }
      else
      {
      str13 = "you need to check";
      }
      }
      LblErr.Visible = true;
      LblErr.Text = str13;

      A Offline
      A Offline
      Anurag Gandhi
      wrote on last edited by
      #2

      If you are talking about the value of LblErr.Text, it will always be according to the checked state of your last item in DataList1. I am sure you can easily guess why is it so. If you want your str13 to have "cheked" for one or multiple checkbox checked, just add a break statement just after the statement str13 = "cheked";

      foreach (DataListItem dli in DataList1.Items)
      {
      CheckBox Chk = (CheckBox)dli.FindControl("CheckBox1");
      if (Chk.Checked)
      {
      str13 = "cheked";
      break;
      }
      else
      {
      str13 = "you need to check";
      }
      }
      LblErr.Visible = true;
      LblErr.Text = str13;

      This should solve your problem.

      Anurag Gandhi.
      http://www.gandhisoft.com
      Life is a computer program and every one is the programmer of his own life.

      T 1 Reply Last reply
      0
      • A Anurag Gandhi

        If you are talking about the value of LblErr.Text, it will always be according to the checked state of your last item in DataList1. I am sure you can easily guess why is it so. If you want your str13 to have "cheked" for one or multiple checkbox checked, just add a break statement just after the statement str13 = "cheked";

        foreach (DataListItem dli in DataList1.Items)
        {
        CheckBox Chk = (CheckBox)dli.FindControl("CheckBox1");
        if (Chk.Checked)
        {
        str13 = "cheked";
        break;
        }
        else
        {
        str13 = "you need to check";
        }
        }
        LblErr.Visible = true;
        LblErr.Text = str13;

        This should solve your problem.

        Anurag Gandhi.
        http://www.gandhisoft.com
        Life is a computer program and every one is the programmer of his own life.

        T Offline
        T Offline
        test 09
        wrote on last edited by
        #3

        thank you bro..:rose:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups