 |
|
 |
thanks for this. you save my day
|
|
|
|
 |
|
|
 |
|
 |
good
|
|
|
|
 |
|
 |
Excellent illustration of how to manage checkboxes in a gridview
|
|
|
|
 |
|
|
 |
|
 |
Worked without a hinge. Good Work
|
|
|
|
 |
|
|
 |
|
 |
It's good article.It solved my purpose.keep posting.
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Very nice..It's working fine..
Good article.keep posting....
|
|
|
|
 |
|
 |
Hey! I found a bug when the checkbox is not the first child control, so I improved your script,
you should make it public!!
Changes: this script loops inside the cell up to 3 levels deep, and when it finds the checkbox does the job and gets out.
Its very useful when you have something like: <div><span><checkbox>
function SelectAll(id)
{
//get reference of GridView control
var grid = document.getElementById("HereTheId");
//variable to contain the cell of the grid
var cell;
if (grid.rows.length > 0)
{
//loop starts from 1. rows[0] points to the header.
for (i=1; i<grid.rows.length; i++)
{
//get the reference of first column
cell = grid.rows[i].cells[0];
//loop according to the number of childNodes in the cell
for (j=0; j<cell.childNodes.length; j++)
{
control=cell.childNodes[j];
for(d=0; d<3;d++) //search up to 3 levels deep
{
//if childNode type is CheckBox
if (control.type =="checkbox")
{
//assign the status of the Select All checkbox to the cell checkbox within the grid
control.checked = document.getElementById(id).checked;
break; //once you find it get out!!
}
if(control.childNodes.length>0)
control=control.childNodes[0];
}
}
}
}
}
|
|
|
|
 |
|
 |
Hi Faraz,
How i do the validation of Gridview
I have outer Grdivew which is binded with Categories Name with Checkbox
and inside ITem Template there is inner Gridview which is displaying the related items Name with (Checkbox) of Category.
Now if i select outergridview row checkbox then its related items checkboxes of inner gridview unselect and if i select any of the inner Gridview Item Checkbox then its Catefory Row Checkbox unselect .
Please help me how i solve this iam stuck on this last few days
Hope Hear from You soon
Best Regards,
|
|
|
|
 |
|
 |
GOod article I am sure people will use it, thanks for sharing.
cheers,
Donsw
My Recent Article : Ajax Calendar Control
|
|
|
|
 |
|
 |
i used the above code
but when i click on check box in headtemplate not happens, not able to select the checkbox
|
|
|
|
 |
|
 |
Hi,
Are you following the steps correctly, because while writing this I checked the code and it was working fine and same goes with the other people commented here. See if you are missing anything. If the problem remains the same then try to paste your code here.
Faraz Shah Khan
MCP, MCAD.Net, MCSD.Net, MCTS-Win/Web, MCPD-Web
Blog
|
|
|
|
 |
|
 |
Hi there. Your code helps a lot.
Programmer's C# { Do it Better;}
|
|
|
|
 |
|
 |
Good to know it helped you.
Faraz Shah Khan
MCP, MCAD.Net, MCSD.Net, MCTS-Win/Web, MCPD-Web
Blog
|
|
|
|
 |
|
 |
Can i request snippet again?
How about finding footer row grid cell values thru javascript?
I'm trying to this all day long but with no luck I'm not able to solve it.
thanks again
Programmer's C# { Do it Better;}
|
|
|
|
 |
|
 |
well I guess grid.rows.length should be equal to last row of the grid i.e footer.
once you get the row you can use the same way to iterate childNodes of a cell.
Faraz Shah Khan
MCP, MCAD.Net, MCSD.Net, MCTS-Win/Web, MCPD-Web
Blog
|
|
|
|
 |
|
 |
here is exact code where can i place the footer row grid cell to find the childnodes?
function ValidateKBandCodex(sender, args) {
var TargetBaseControl = document.getElementById("<%=gvProducts.ClientID %>");
var TargetChildControl;
var TargetChildControl2;
var chkCodex;
var chkKB;
if (TargetBaseControl.rows.length > 0)
{
for(i= 0;i<targetbasecontrol.rows.length;i++)>
{
TargetChildControl = TargetBaseControl.rows[i].cells[2];
TargetChildControl2 = TargetBaseControl.rows[i].cells[3];
for (j = 0;j < TargetChildControl.childNodes.length; j++)
{
if (TargetChildControl.childNodes[j].type =="checkbox")
{
chkCodex= TargetChildControl.childNodes[j].checked;
}
}
for(x = 0;x < TargetChildControl2.childNodes.length;x++)
{
if (TargetChildControl2.childNodes[x].type =="checkbox")
{
chkKB = TargetChildControl2.childNodes[x].checked;
}
}
}
args.IsValid = (chkCodex == true || chkKB == true);
}
}
Programmer's C# { Do it Better;}
|
|
|
|
 |
|
 |
try this
function ValidateKBandCodex(sender, args)
{
var TargetBaseControl = document.getElementById("<%=gvProducts.ClientID %>");
var TargetChildControl;
var TargetChildControl2;
var chkCodex;
var chkKB;
if (TargetBaseControl.rows.length > 0)
{
for(i= 0;i<targetbasecontrol.rows.length;i++)
{
TargetChildControl = TargetBaseControl.rows[i].cells[2];
TargetChildControl2 = TargetBaseControl.rows[i].cells[3];
for (j = 0;j < TargetChildControl.childNodes.length; j++)
{
if (TargetChildControl.childNodes[j].type =="checkbox")
{
chkCodex= TargetChildControl.childNodes[j].checked;
}
}
for(x = 0;x < TargetChildControl2.childNodes.length;x++)
{
if (TargetChildControl2.childNodes[i].type =="checkbox")
{
chkKB = TargetChildControl2.childNodes[i].checked;
}
}
}
//try to place your code here
var lrow = TargetBaseControl.rows[TargetBaseControl.rows.length];
//do your task. I hope it will work
args.IsValid = (chkCodex == true || chkKB == true);
}
} ...(continued)
Faraz Shah Khan
MCP, MCAD.Net, MCSD.Net, MCTS-Win/Web, MCPD-Web
Blog
|
|
|
|
 |
|
 |
the sample is fully working from its original. but when I apply it in my own sample project it only works when the checkbox is place on the first column. in my project i put the checkbox at column 6 then when i test to run I got an error: "Microsoft JScript runtime error: 'childNodes' is null or not an object"
Any help pls.
function SelectAll(id) {
//get reference of GridView control
var grid = document.getElementById("<%= gvConfirm.ClientID %>");
//variable to contain the cell of the grid
var cell;
if (grid.rows.length > 0) {
//loop starts from 1. rows[0] points to the header.
for (i = 1; i < grid.rows.length; i++) {
//get the reference of first column
cell = grid.rows[i].cells[6];
//loop according to the number of childNodes in the cell
for (j = 0; j < cell.childNodes.length; j++) {
//if childNode type is CheckBox
if (cell.childNodes[j].type == "checkbox") {
//assign the status of the Select All checkbox to the cell checkbox within the grid
cell.childNodes[j].checked = document.getElementById(id).checked;
}
}
}
}
}
|
|
|
|
 |
|
 |
try to modify this line with index 5
cell = grid.rows[i].cells[5]; //since the index starts from 0, column 6 should be on index 5
Faraz Shah Khan
MCP, MCAD.Net, MCSD.Net, MCTS-Win/Web, MCPD-Web
Blog
|
|
|
|
 |
|
|
 |