how to get the count
-
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
send your code, so that i can check it
Padmanabhan
-
send your code, so that i can check it
Padmanabhan
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
-
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
your aspx code plz
Padmanabhan
-
your aspx code plz
Padmanabhan
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"/>
-
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"/>
onclick = "Check_Click(this)" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged1" /> //delete that onclick = "Check_Click(this)" event and check.
Padmanabhan
-
onclick = "Check_Click(this)" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged1" /> //delete that onclick = "Check_Click(this)" event and check.
Padmanabhan
//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
-
onclick = "Check_Click(this)" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged1" /> //delete that onclick = "Check_Click(this)" event and check.
Padmanabhan
Thank you... Thanx alot...For helping me Now i am geting the count. :)
-
Thank you... Thanx alot...For helping me Now i am geting the count. :)
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
-
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
//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
-
//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
Thank you... Thanx a million for helping me...
-
Thank you... Thanx a million for helping me...
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