By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,230 Members | 2,471 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,230 IT Pros & Developers. It's quick & easy.

Javascript error on empty GridView

P: 9
Hi all,
I am working on a GridView and there exist a Checkbox control .. iplaced another checkbox in header also i have written a javascript for selection of checkboxex fro e.g if you click on header checkbox that script will select all the child checkboxes its working fine but when that gridview doesn,t contain anything at that time this script is throwing an error i am sending the code also immidiately help needed
window.onload = function()
{
var gridv=document.getElementById('<%= this.grvFinApproval.ClientID %>');
TotalChkBx = <%=this.grvFinApproval.Rows.Count%>;
alert(TotalChkBx);
Counter = 0;
}
function HeaderClick(CheckBox)
{
var TargetBaseControl = document.getElementById('<%= this.grvFinApproval.ClientID %>');
if(TargetBaseControl!=null) //not working
{
var TargetBaseControl = document.getElementById('<%= this.grvFinApproval.ClientID %>');
var TargetChildControl = "chkFinApproval";
var Inputs = TargetBaseControl.getElementsByTagName("input");
for(var n = 0; n < Inputs.length; ++n)
if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0)
Inputs[n].checked = CheckBox.checked;
Counter = CheckBox.checked ? TotalChkBx : 0;
}
}
function ChildClick(CheckBox)
{
var HeaderCheckBox = document.getElementById('<%= this.grvFinApproval.HeaderRow.FindControl("chkCell ").ClientID %>');
if(HeaderCheckBox!=null) //not working
{
if(CheckBox.checked && Counter < TotalChkBx)
Counter++;
else if(Counter > 0)
Counter--;
if(Counter < TotalChkBx)
HeaderCheckBox.checked = false;
else if(Counter == TotalChkBx)
HeaderCheckBox.checked = true;
}

}
Jun 18 '08 #1
Share this Question
Share on Google+
6 Replies


10K+
P: 13,264
What is the error message that you get?
Jun 18 '08 #2

P: 9
What is the error message that you get?
System.NullReferenceException: Object reference not set to an instance of an object.
Jun 18 '08 #3

10K+
P: 13,264
System.NullReferenceException: Object reference not set to an instance of an object.
Can you try to get the line (number) where that exception is thrown from?
Jun 18 '08 #4

P: 9
Can you try to get the line (number) where that exception is thrown from?
This is the line in Child_CLick
var HeaderCheckBox = document.getElementById('<%= this.grvFinApproval.HeaderRow.FindControl("chkCell ").ClientID %>');
Jun 19 '08 #5

10K+
P: 13,264
Check whether grvFinApproval.HeaderRow.FindControl("chkCell") is not null by a simple
Expand|Select|Wrap|Line Numbers
  1. if(grvFinApproval.HeaderRow.FindControl("chkCell") == null) {
  2. //output something here to indicate that it's null
  3. }
If you get some output from the if then it explains why
grvFinApproval.HeaderRow.FindControl("chkCell").Cl ientID will throw a null reference exception.
Jun 19 '08 #6

P: 9
Check whether grvFinApproval.HeaderRow.FindControl("chkCell") is not null by a simple
Expand|Select|Wrap|Line Numbers
  1. if(grvFinApproval.HeaderRow.FindControl("chkCell") == null) {
  2. //output something here to indicate that it's null
  3. }
If you get some output from the if then it explains why
grvFinApproval.HeaderRow.FindControl("chkCell").Cl ientID will throw a null reference exception.
If we dont show the gridview still this script searching for that checkbox...How do i prevent this searching initiated by javascript
Jun 19 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.