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. how to get the count

how to get the count

Scheduled Pinned Locked Moved ASP.NET
tutorial
19 Posts 3 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.
  • A Anjani Poornima

    hi, I done all the things guided by you. But i am unable to get the count after immedialtely checking the chechbox. Is there any alternate i tried alot but failed. its very urgent for me. plz help me. Thanks in advance

    P Offline
    P Offline
    padmanabhan N
    wrote on last edited by
    #9

    send your code, so that i can check it

    Padmanabhan

    A 1 Reply Last reply
    0
    • P padmanabhan N

      send your code, so that i can check it

      Padmanabhan

      A Offline
      A Offline
      Anjani Poornima
      wrote on last edited by
      #10

      public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void gridview1_SelectedIndexChanged(object sender, EventArgs e) { } protected void CheckBox1_CheckedChanged1(object sender, EventArgs e) { int count = 0; for (int i = 0; i < gridview1.Rows.Count; i++) { GridViewRow rows = gridview1.Rows[i]; bool ischeck = ((CheckBox)rows.FindControl("CheckBox1")).Checked; if (ischeck) { count = count + 1; Label1.Text = Convert.ToString(count); } } } protected void btnsubmit_Click(object sender, EventArgs e) { StringBuilder str = new StringBuilder(); for (int i = 0; i < gridview1.Rows.Count; i++) { GridViewRow row = gridview1.Rows[i]; bool ischecked = ((CheckBox)row.FindControl("CheckBox1")).Checked; if (ischecked) { str.Append(gridview1.Rows[i].Cells[2].Text); } } Response.Write(str.ToString()); } } Here is my code... plz help where i missed to get the count. thanks in advance

      P 1 Reply Last reply
      0
      • A Anjani Poornima

        public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void gridview1_SelectedIndexChanged(object sender, EventArgs e) { } protected void CheckBox1_CheckedChanged1(object sender, EventArgs e) { int count = 0; for (int i = 0; i < gridview1.Rows.Count; i++) { GridViewRow rows = gridview1.Rows[i]; bool ischeck = ((CheckBox)rows.FindControl("CheckBox1")).Checked; if (ischeck) { count = count + 1; Label1.Text = Convert.ToString(count); } } } protected void btnsubmit_Click(object sender, EventArgs e) { StringBuilder str = new StringBuilder(); for (int i = 0; i < gridview1.Rows.Count; i++) { GridViewRow row = gridview1.Rows[i]; bool ischecked = ((CheckBox)row.FindControl("CheckBox1")).Checked; if (ischecked) { str.Append(gridview1.Rows[i].Cells[2].Text); } } Response.Write(str.ToString()); } } Here is my code... plz help where i missed to get the count. thanks in advance

        P Offline
        P Offline
        padmanabhan N
        wrote on last edited by
        #11

        your aspx code plz

        Padmanabhan

        A 1 Reply Last reply
        0
        • P padmanabhan N

          your aspx code plz

          Padmanabhan

          A Offline
          A Offline
          Anjani Poornima
          wrote on last edited by
          #12

          script type = "text/javascript"> function checkAll(objRef) { var GridView = objRef.parentNode.parentNode.parentNode; var inputList = GridView.getElementsByTagName("input"); for (var i=0;i<inputList.length;i++) { //Get the Cell To find out ColumnIndex var row = inputList[i].parentNode.parentNode; if(inputList[i].type == "checkbox" && objRef != inputList[i]) { if (objRef.checked) { //If the header checkbox is checked //check all checkboxes //and highlight all rows //row.style.backgroundColor = "aqua"; inputList[i].checked=true; } else { //If the header checkbox is checked //uncheck all checkboxes //and change rowcolor back to original //if(row.rowIndex % 2 == 0) //{ //Alternating Row Color // row.style.backgroundColor = "#C2D69B"; // } // else //{ //row.style.backgroundColor = "white"; //} inputList[i].checked=false; } } } } /script /head body

          < PagerStyle CssClass="mypager" HorizontalAlign="Right"/>

          P 1 Reply Last reply
          0
          • A Anjani Poornima

            script type = "text/javascript"> function checkAll(objRef) { var GridView = objRef.parentNode.parentNode.parentNode; var inputList = GridView.getElementsByTagName("input"); for (var i=0;i<inputList.length;i++) { //Get the Cell To find out ColumnIndex var row = inputList[i].parentNode.parentNode; if(inputList[i].type == "checkbox" && objRef != inputList[i]) { if (objRef.checked) { //If the header checkbox is checked //check all checkboxes //and highlight all rows //row.style.backgroundColor = "aqua"; inputList[i].checked=true; } else { //If the header checkbox is checked //uncheck all checkboxes //and change rowcolor back to original //if(row.rowIndex % 2 == 0) //{ //Alternating Row Color // row.style.backgroundColor = "#C2D69B"; // } // else //{ //row.style.backgroundColor = "white"; //} inputList[i].checked=false; } } } } /script /head body

            < PagerStyle CssClass="mypager" HorizontalAlign="Right"/>

            P Offline
            P Offline
            padmanabhan N
            wrote on last edited by
            #13

            onclick = "Check_Click(this)" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged1" /> //delete that onclick = "Check_Click(this)" event and check.

            Padmanabhan

            P A 2 Replies Last reply
            0
            • P padmanabhan N

              onclick = "Check_Click(this)" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged1" /> //delete that onclick = "Check_Click(this)" event and check.

              Padmanabhan

              P Offline
              P Offline
              padmanabhan N
              wrote on last edited by
              #14

              //aspx.cs page using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; using System.Globalization; using System.Text; public partial class Text : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DataTable dt = new DataTable(); dt.Columns.Add("Name", typeof(String)); DataRow dr = dt.NewRow(); dr["Name"] = "Padmanabhan"; dt.Rows.Add(dr); DataRow dr1 = dt.NewRow(); dr1["Name"] = "Varatharaman"; dt.Rows.Add(dr1); DataRow dr2 = dt.NewRow(); dr2["Name"] = "Sathya"; dt.Rows.Add(dr2); GridView1.DataSource = dt; GridView1.DataBind(); } } protected void CheckBox1_CheckedChanged1(object sender, EventArgs e) { int count = 0; for (int i = 0; i < GridView1.Rows.Count; i++) { GridViewRow rows = GridView1.Rows[i]; bool ischeck = ((CheckBox)rows.FindControl("CheckBox1")).Checked; if (ischeck) { count = count+1; Label1.Text = Convert.ToString(count); } } } protected void Button1_Click(object sender, EventArgs e) { StringBuilder str = new StringBuilder(); for (int i = 0; i < GridView1.Rows.Count; i++) { GridViewRow row = GridView1.Rows[i]; bool ischecked = ((CheckBox)row.FindControl("CheckBox1")).Checked; if (ischecked) { str.Append(GridView1.Rows[i].Cells[0].Text); } } Response.Write(str.ToString()); } } //aspx page <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Text.aspx.cs" Inherits="Text" %> Untitled Page

              1 Reply Last reply
              0
              • P padmanabhan N

                onclick = "Check_Click(this)" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged1" /> //delete that onclick = "Check_Click(this)" event and check.

                Padmanabhan

                A Offline
                A Offline
                Anjani Poornima
                wrote on last edited by
                #15

                Thank you... Thanx alot...For helping me Now i am geting the count. :)

                A 1 Reply Last reply
                0
                • A Anjani Poornima

                  Thank you... Thanx alot...For helping me Now i am geting the count. :)

                  A Offline
                  A Offline
                  Anjani Poornima
                  wrote on last edited by
                  #16

                  hello sir, And one more question regarding this checkbox count. when i have not selected any checkbox the label must show "no records selected". I tried this by using else block but failing to get and i am having "select all" checkbox at the top and when i checked that selectall checkbox it must similarly show the count.. Plz,help me.... i am very new to this asp.net world.. Thanks in advance

                  P 1 Reply Last reply
                  0
                  • A Anjani Poornima

                    hello sir, And one more question regarding this checkbox count. when i have not selected any checkbox the label must show "no records selected". I tried this by using else block but failing to get and i am having "select all" checkbox at the top and when i checked that selectall checkbox it must similarly show the count.. Plz,help me.... i am very new to this asp.net world.. Thanks in advance

                    P Offline
                    P Offline
                    padmanabhan N
                    wrote on last edited by
                    #17

                    //java script var TotalChkBx; var Counter; window.onload = function() { TotalChkBx = parseInt('<%= this.GridView1.Rows.Count %>'); Counter = 0; } function SelectAll(CheckBox) { var TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>'); var TargetChildControl = "CheckBox1"; var Inputs = TargetBaseControl.getElementsByTagName("input"); for(var n = 0; n < Inputs.length; ++n) if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0) Inputs[n].checked = CheckBox.checked; Counter = CheckBox.checked ? TotalChkBx : 0; if(Counter !=0) document.getElementById('Label1').innerText = Counter; else document.getElementById('Label1').innerText = "no records selected"; } //in your aspx //your aspx.cs page protected void CheckBox1_CheckedChanged1(object sender, EventArgs e) { int count = 0; for (int i = 0; i < GridView1.Rows.Count; i++) { GridViewRow rows = GridView1.Rows[i]; bool ischeck = ((CheckBox)rows.FindControl("CheckBox1")).Checked; if (ischeck) { count = count+1; } if (count != 0) { Label1.Text = Convert.ToString(count); } else { Label1.Text = "no records selected"; } } }

                    Padmanabhan

                    modified on Thursday, May 28, 2009 4:20 AM

                    A 1 Reply Last reply
                    0
                    • P padmanabhan N

                      //java script var TotalChkBx; var Counter; window.onload = function() { TotalChkBx = parseInt('<%= this.GridView1.Rows.Count %>'); Counter = 0; } function SelectAll(CheckBox) { var TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>'); var TargetChildControl = "CheckBox1"; var Inputs = TargetBaseControl.getElementsByTagName("input"); for(var n = 0; n < Inputs.length; ++n) if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0) Inputs[n].checked = CheckBox.checked; Counter = CheckBox.checked ? TotalChkBx : 0; if(Counter !=0) document.getElementById('Label1').innerText = Counter; else document.getElementById('Label1').innerText = "no records selected"; } //in your aspx //your aspx.cs page protected void CheckBox1_CheckedChanged1(object sender, EventArgs e) { int count = 0; for (int i = 0; i < GridView1.Rows.Count; i++) { GridViewRow rows = GridView1.Rows[i]; bool ischeck = ((CheckBox)rows.FindControl("CheckBox1")).Checked; if (ischeck) { count = count+1; } if (count != 0) { Label1.Text = Convert.ToString(count); } else { Label1.Text = "no records selected"; } } }

                      Padmanabhan

                      modified on Thursday, May 28, 2009 4:20 AM

                      A Offline
                      A Offline
                      Anjani Poornima
                      wrote on last edited by
                      #18

                      Thank you... Thanx a million for helping me...

                      P 1 Reply Last reply
                      0
                      • A Anjani Poornima

                        Thank you... Thanx a million for helping me...

                        P Offline
                        P Offline
                        padmanabhan N
                        wrote on last edited by
                        #19

                        This is my Article. If you have any doubt in Grid related refer this site and vote if you like it. GridView all in one[^]

                        Padmanabhan

                        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