Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 09, 2011 11:52 AM by mudassarkhan
Member
258 Points
51 Posts
Jun 29, 2005 01:39 PM|LINK
65 Points
13 Posts
Dec 23, 2005 04:58 PM|LINK
4 Points
2 Posts
Feb 01, 2007 02:37 AM|LINK
It could be done in JavaScript, but I am 2 lazy. So thats what I did.... [:D]
protected void chkbSelectAll_CheckedChanged(object sender, EventArgs e) { bool chkFlag = false; if (chkbSelectAll.Checked) chkFlag = true; foreach (GridViewRow dr in gvProducts.Rows) { CheckBox chk = (CheckBox)dr.Cells[0].FindControl("Select"); chk.Checked = chkFlag; } }
ASP.net 2.0 GridView InsertParameters ControlParameter PropertyName
Contributor
5464 Points
917 Posts
Feb 01, 2007 02:46 AM|LINK
Participant
925 Points
254 Posts
Feb 01, 2007 02:55 AM|LINK
What type of functionality u r willing to implement.
if planning for a serverside one. Its pretty easy.
for client side one without postback u have to do with javascript
Just do like this
select: all | none
all is clicked v will call SelectAll(true) otherwise SelectAll(false) is called
function selectAll(on) {
var allElts = document.forms['f'].elements;
var i;
for (i=0; i<allElts.length; i++) {
var elt = allElts[i];
if (elt.type == "checkbox") {
elt.checked = on;
}
function getSelectedUserIds() {
var selectedList = new Array();
if (elt.name == "friendCheckbox") {
if (elt.checked) {
selectedList[selectedList.length] = elt.id;
return selectedList;
or just check this link
http://aspnet.4GuysFromRolla.com//articles/053106-1.aspx
Feb 01, 2007 03:00 AM|LINK
18 Points
9 Posts
Dec 09, 2008 11:17 AM|LINK
Please use this code
Javascript code is better,but it is not fine in case of multiple grid on aspx page.
So this code is much better in server side.
protected void chkheader_CheckedChanged(object sender, EventArgs e) { CheckBox chk = (CheckBox)gv.HeaderRow.FindControl("chkheader"); if (chk.Checked) { for (int i = 0; i < gv.Rows.Count; i++) { CheckBox chkrow = (CheckBox)gv.Rows[i].FindControl("chkbox"); chkrow.Checked = true; } } else { for (int i = 0; i < gvRemmitance.Rows.Count; i++) { CheckBox chkrow = (CheckBox)gv.Rows[i].FindControl("chkbox"); chkrow.Checked = false; } } }
Thanks and Regards
Mrutyunjay Palai
32 Points
7 Posts
Dec 22, 2008 07:06 AM|LINK
I used jQuery to write only 10 line javascript code to do this. This script is completely independent of code behind:
http://ashishware.com/CheckBoxJs.shtml
chrisbond
Member
258 Points
51 Posts
GridView Checkbox Select All
Jun 29, 2005 01:39 PM|LINK
hopskipjump
Member
65 Points
13 Posts
Re: GridView Checkbox Select All
Dec 23, 2005 04:58 PM|LINK
xvxOlegxvx
Member
4 Points
2 Posts
Re: GridView Checkbox Select All
Feb 01, 2007 02:37 AM|LINK
It could be done in JavaScript, but I am 2 lazy. So thats what I did.... [:D]
protected void chkbSelectAll_CheckedChanged(object sender, EventArgs e) { bool chkFlag = false; if (chkbSelectAll.Checked) chkFlag = true; foreach (GridViewRow dr in gvProducts.Rows) { CheckBox chk = (CheckBox)dr.Cells[0].FindControl("Select"); chk.Checked = chkFlag; } }ASP.net 2.0 GridView InsertParameters ControlParameter PropertyName
CSharpSean
Contributor
5464 Points
917 Posts
Re: GridView Checkbox Select All
Feb 01, 2007 02:46 AM|LINK
Checking all CheckBoxes in a GridView from Header
sreejith77
Participant
925 Points
254 Posts
Re: GridView Checkbox Select All
Feb 01, 2007 02:55 AM|LINK
What type of functionality u r willing to implement.
if planning for a serverside one. Its pretty easy.
for client side one without postback u have to do with javascript
Just do like this
select: all | none
all is clicked v will call SelectAll(true) otherwise SelectAll(false) is called
function selectAll(on) {
var allElts = document.forms['f'].elements;
var i;
for (i=0; i<allElts.length; i++) {
var elt = allElts[i];
if (elt.type == "checkbox") {
elt.checked = on;
}
}
}
function getSelectedUserIds() {
var allElts = document.forms['f'].elements;
var i;
var selectedList = new Array();
for (i=0; i<allElts.length; i++) {
var elt = allElts[i];
if (elt.name == "friendCheckbox") {
if (elt.checked) {
selectedList[selectedList.length] = elt.id;
}
}
}
return selectedList;
}
or just check this link
http://aspnet.4GuysFromRolla.com//articles/053106-1.aspx
http://tips4dotnet.blogspot.com/
sreejith77
Participant
925 Points
254 Posts
Re: GridView Checkbox Select All
Feb 01, 2007 02:55 AM|LINK
What type of functionality u r willing to implement.
if planning for a serverside one. Its pretty easy.
for client side one without postback u have to do with javascript
Just do like this
select: all | none
all is clicked v will call SelectAll(true) otherwise SelectAll(false) is called
function selectAll(on) {
var allElts = document.forms['f'].elements;
var i;
for (i=0; i<allElts.length; i++) {
var elt = allElts[i];
if (elt.type == "checkbox") {
elt.checked = on;
}
}
}
function getSelectedUserIds() {
var allElts = document.forms['f'].elements;
var i;
var selectedList = new Array();
for (i=0; i<allElts.length; i++) {
var elt = allElts[i];
if (elt.name == "friendCheckbox") {
if (elt.checked) {
selectedList[selectedList.length] = elt.id;
}
}
}
return selectedList;
}
or just check this link
http://aspnet.4GuysFromRolla.com//articles/053106-1.aspx
http://tips4dotnet.blogspot.com/
sreejith77
Participant
925 Points
254 Posts
Re: GridView Checkbox Select All
Feb 01, 2007 02:55 AM|LINK
What type of functionality u r willing to implement.
if planning for a serverside one. Its pretty easy.
for client side one without postback u have to do with javascript
Just do like this
select: all | none
all is clicked v will call SelectAll(true) otherwise SelectAll(false) is called
function selectAll(on) {
var allElts = document.forms['f'].elements;
var i;
for (i=0; i<allElts.length; i++) {
var elt = allElts[i];
if (elt.type == "checkbox") {
elt.checked = on;
}
}
}
function getSelectedUserIds() {
var allElts = document.forms['f'].elements;
var i;
var selectedList = new Array();
for (i=0; i<allElts.length; i++) {
var elt = allElts[i];
if (elt.name == "friendCheckbox") {
if (elt.checked) {
selectedList[selectedList.length] = elt.id;
}
}
}
return selectedList;
}
or just check this link
http://aspnet.4GuysFromRolla.com//articles/053106-1.aspx
http://tips4dotnet.blogspot.com/
xvxOlegxvx
Member
4 Points
2 Posts
Re: GridView Checkbox Select All
Feb 01, 2007 03:00 AM|LINK
mrutyunjaypa...
Member
18 Points
9 Posts
Re: GridView Checkbox Select All
Dec 09, 2008 11:17 AM|LINK
Please use this code
Javascript code is better,but it is not fine in case of multiple grid on aspx page.
So this code is much better in server side.
protected void chkheader_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)gv.HeaderRow.FindControl("chkheader");
if (chk.Checked)
{
for (int i = 0; i < gv.Rows.Count; i++)
{
CheckBox chkrow = (CheckBox)gv.Rows[i].FindControl("chkbox");
chkrow.Checked = true;
}
}
else
{
for (int i = 0; i < gvRemmitance.Rows.Count; i++)
{
CheckBox chkrow = (CheckBox)gv.Rows[i].FindControl("chkbox");
chkrow.Checked = false;
}
}
}
Thanks and Regards
Mrutyunjay Palai
geek111222
Member
32 Points
7 Posts
Re: GridView Checkbox Select All
Dec 22, 2008 07:06 AM|LINK
I used jQuery to write only 10 line javascript code to do this. This script is completely independent of code behind:
http://ashishware.com/CheckBoxJs.shtml
Ashish
http://ashishware.com