| | |
checkbox in datagrid
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2007
Posts: 29
Reputation:
Solved Threads: 0
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; } } } }
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.
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. •
•
Join Date: Jan 2007
Posts: 29
Reputation:
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
•
•
Join Date: Jan 2007
Posts: 47
Reputation:
Solved Threads: 0
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>
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>
•
•
Join Date: Jan 2007
Posts: 29
Reputation:
Solved Threads: 0
•
•
•
•
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
•
•
Join Date: Jan 2007
Posts: 29
Reputation:
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.
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.
![]() |
Similar Threads
- select row in datagrid....need help (VB.NET)
- to make checkboxes visible in datagrid C# windows application (C#)
- hide checkbox when field value is null (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: how to read a file from client side without browsing
- Next Thread: how to create forums?
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 3.5 activexcontrol advice ajax appliances asp asp.net beginner bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn cac checkbox child class click compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datalist deadlock deployment development dgv dialog dropdown dropdownmenu dynamic edit embeddingactivexcontrol feedback findcontrol flash flv folder form forms grid gridview homeedition hosting iframe iis index javascript jquery list maps menu mobile mono mssql multistepregistration nameisnotdeclared novell objects order problem ratings refer rotatepage search security serializesmo.table sessionvariables silverlight smartcard sql ssl tracking treeview typeof update validatedate validation vb.net view virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopment wizard xml






