944,057 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 12859
  • ASP.NET RSS
Feb 2nd, 2007
0

checkbox in datagrid

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
hkarthik is offline Offline
29 posts
since Jan 2007
Feb 2nd, 2007
0

Re: checkbox in datagrid

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.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Feb 2nd, 2007
0

Re: checkbox in datagrid

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; } } }
Reputation Points: 10
Solved Threads: 0
Light Poster
kapil.goyal is offline Offline
47 posts
since Jan 2007
Feb 5th, 2007
0

Re: checkbox in datagrid

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
Reputation Points: 10
Solved Threads: 0
Light Poster
hkarthik is offline Offline
29 posts
since Jan 2007
Feb 5th, 2007
0

Re: checkbox in datagrid

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>
Reputation Points: 10
Solved Threads: 0
Light Poster
kapil.goyal is offline Offline
47 posts
since Jan 2007
Feb 6th, 2007
0

Re: checkbox in datagrid

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
Reputation Points: 10
Solved Threads: 0
Light Poster
hkarthik is offline Offline
29 posts
since Jan 2007
Feb 7th, 2007
0

Re: checkbox in datagrid

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

Re: checkbox in datagrid

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
hkarthik is offline Offline
29 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: how to read a file from client side without browsing
Next Thread in ASP.NET Forum Timeline: how to create forums?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC