Solved

checkall for checkboxes in gridview

Posted on 2008-06-11
3
395 Views
Last Modified: 2008-07-05
In my  gridview  I have a checkbox  column , so, I have a check box as a header for that column.
The interaction part I want to use javascript. Does anyone have a good sample code for me ?
Thank you,


     
0
Comment
Question by:sunisagar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Expert Comment

by:Qaiser_Mehmood_Mughal
ID: 21766638
For complete details check this link. hope this will help u

http://www.shiningstar.net/articles/articles/javascript/checkboxes.asp


<SCRIPT LANGUAGE="JavaScript">
<!--       
// by Nannette Thacker
// http://www.shiningstar.net
// This script checks and unchecks boxes on a form
// Checks and unchecks unlimited number in the group...
// Pass the Checkbox group name...
// call buttons as so:
// <input type=button name="CheckAll"   value="Check All"
      //onClick="checkAll(document.myform.list)">
// <input type=button name="UnCheckAll" value="Uncheck All"
      //onClick="uncheckAll(document.myform.list)">
// -->

<!-- Begin
function checkAll(field)
{
for (i = 0; i < field.length; i++)
      field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
      field[i].checked = false ;
}
//  End -->
</script>
0
 
LVL 5

Expert Comment

by:Qaiser_Mehmood_Mughal
ID: 21766647
This link is also very nice, and its for gridview control checkboxs.

http://weblog.vb-tech.com/nick/archive/2005/09/26/1300.aspx

function doAllChecks()
{
 re = new RegExp('_chkMove')


 if(document.Form1['Datagrid1_ctl1_chkAction'].checked == true)
 {
   for (var iCount=0;iCount
  {
   elm = document.forms[0].elements[iCount]

    if (elm.type == 'checkbox') {

     if (re.test(elm.id)) {
      elm.checked = true;
     }
    }
   
  }
 }
 else
 {
 
 
  for (var iCount=0;iCount
  {
   elm = document.forms[0].elements[iCount]

    if (elm.type == 'checkbox') {

     if (re.test(elm.id)) {
      elm.checked = false;
     }
    }
   
  }
 }
}
0
 

Accepted Solution

by:
sunisagar earned 0 total points
ID: 21782338
Do you have a working  sample of this ?.
What if one of the checkboxes get uncheck in the gridview tahn we have to uncheck the checkbox in the header, How to do that?.

And in the code  " if(document.Form1['Datagrid1_ctl1_chkAction'].checked == true)
"
is Datagrid1_ctl_chkAction" the id of the header checkbox ?
and about the regular expression  re = new RegExp('_chkMove')
waht happens here ?. what is  "_chkMove"  the id of the checkbox in the columns ?

Please attach a sample working code if you haveone for the GridView
Thank you
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question