checkbox in datagrid

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2007
Posts: 29
Reputation: hkarthik is an unknown quantity at this point 
Solved Threads: 0
hkarthik hkarthik is offline Offline
Light Poster

checkbox in datagrid

 
0
  #1
Feb 2nd, 2007
hi,

how do we select multiple checkboxes in datagrid using a checkbox in the header of that datagrid. I went successful in adding each check boxes to each row. Now insted of selecting each checkbox individually i used a checkbox in the header of that datagrid. So when i check this, all the checkboxes in my datagrid should get selected and when i deselect the reverse should happen. How can i do this. I tried it this way

var checkflag="false"; var re; function checkall(aspCheckBoxID, checkVal) { re = new RegExp(':' + aspCheckBoxID + '$'); for(i = 0; document.forms[0].elements.length; i++) { elm = document.forms[0].elements[i]; if (elm.type == 'checkbox') { if (re.test(elm.name)) { elm.checked = checkVal; } } } }
Last edited by hkarthik; Feb 2nd, 2007 at 6:41 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: checkbox in datagrid

 
0
  #2
Feb 2nd, 2007
I'm not sure this document.forms[0].elements gets all the nested child elements and the checkboxes will be nested down in table/tr/td dom elements. try var elements = document.getElementsByTagName("input"); and iterate that instead.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 47
Reputation: kapil.goyal is an unknown quantity at this point 
Solved Threads: 0
kapil.goyal kapil.goyal is offline Offline
Light Poster

Re: checkbox in datagrid

 
0
  #3
Feb 2nd, 2007
just try this

this vl solve the problem


function checkAll(o) { for (var i = 0; i < document.Form1.elements.length; i++) { if (document.Form1.elements[i].type == "checkbox") { document.Form1.elements[i].checked = o.checked; } } }
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 29
Reputation: hkarthik is an unknown quantity at this point 
Solved Threads: 0
hkarthik hkarthik is offline Offline
Light Poster

Re: checkbox in datagrid

 
0
  #4
Feb 5th, 2007
Originally Posted by kapil.goyal View Post
just try this

this vl solve the problem


function checkAll(o) { for (var i = 0; i < document.Form1.elements.length; i++) { if (document.Form1.elements[i].type == "checkbox") { document.Form1.elements[i].checked = o.checked; } } }

hi kapil,
i tried but i couldn't get the solution. Can you excatly tell me the process from the beginning, so that i can check whether i have made any mistake or not. Like, from adding the checkbox into the datagrid till the selection. Please
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 47
Reputation: kapil.goyal is an unknown quantity at this point 
Solved Threads: 0
kapil.goyal kapil.goyal is offline Offline
Light Poster

Re: checkbox in datagrid

 
0
  #5
Feb 5th, 2007
just follow this process

create a template column and add this code to tat

<HeaderTemplate>
<input runat="server" type="checkbox" ID="chkSelectAll" title="Select All Files" onclick="checkAll(this);" NAME="chkSelectAll" />
</HeaderTemplate>

and add the following code under HEAD tag of HTML code


<script language="javascript" type="text/javascript">
function checkAll(o) {
for (var i = 0; i < document.Form1.elements.length; i++) {
if (document.Form1.elements[i].type == "checkbox") {
document.Form1.elements[i].checked = o.checked;
}
}
}
</script>
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 29
Reputation: hkarthik is an unknown quantity at this point 
Solved Threads: 0
hkarthik hkarthik is offline Offline
Light Poster

Re: checkbox in datagrid

 
0
  #6
Feb 6th, 2007
Originally Posted by kapil.goyal View Post
just follow this process

create a template column and add this code to tat

<HeaderTemplate>
<input runat="server" type="checkbox" ID="chkSelectAll" title="Select All Files" onclick="checkAll(this);" NAME="chkSelectAll" />
</HeaderTemplate>

and add the following code under HEAD tag of HTML code


<script language="javascript" type="text/javascript">
function checkAll(o) {
for (var i = 0; i < document.Form1.elements.length; i++) {
if (document.Form1.elements[i].type == "checkbox") {
document.Form1.elements[i].checked = o.checked;
}
}
}
</script>

hi kapil,

I tried it another way and got the solution. Ikept a command button above my dgrid and wrote coding like if true then make it false and if false then make it true.But now the problem is all the checkbox's which are inside my datagrid are having the same name. So if i want to select some particular checkboxes inside my datagrid and do transactions for that particular checkboxes means, how should i select that. For example if i want to send some message to only some selected persons from the list means how can i do it
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 47
Reputation: kapil.goyal is an unknown quantity at this point 
Solved Threads: 0
kapil.goyal kapil.goyal is offline Offline
Light Poster

Re: checkbox in datagrid

 
0
  #7
Feb 7th, 2007
take a label in item template inside the template column containg header template.assign the field to label on which you want to perform operation like primary key.and make label visible false.and access the check box by label value.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 29
Reputation: hkarthik is an unknown quantity at this point 
Solved Threads: 0
hkarthik hkarthik is offline Offline
Light Poster

Re: checkbox in datagrid

 
0
  #8
Feb 7th, 2007
Originally Posted by kapil.goyal View Post
take a label in item template inside the template column containg header template.assign the field to label on which you want to perform operation like primary key.and make label visible false.and access the check box by label value.
hi kapil,

This is little bit confusing. Can you be little more clear. Actually i want to send message to the selected user's in my datagrid. My datagrid consists of three columns. The first one consists of a checkbox, the second and third consists of label's. So i want to get the value that is in the third column for all the checked chkbox in my first column. So How to get the value for the checked chkboxes.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC