954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

checkbox in datagrid

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; } } } }

hkarthik
Light Poster
29 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

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.

hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
 

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; } } }

kapil.goyal
Light Poster
47 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 
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

hkarthik
Light Poster
29 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

just follow this process

create a template column and add this code to tat



and add the following code under HEAD tag of HTML code


kapil.goyal
Light Poster
47 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 
just follow this process create a template column and add this code to tat and add the following code under HEAD tag of HTML code




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

hkarthik
Light Poster
29 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

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.

kapil.goyal
Light Poster
47 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 
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.

hkarthik
Light Poster
29 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You