473,378 Members | 1,138 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Javascript error on empty GridView

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
6 4012
r035198x
13,262 8TB
What is the error message that you get?
Jun 18 '08 #2
What is the error message that you get?
System.NullReferenceException: Object reference not set to an instance of an object.
Jun 18 '08 #3
r035198x
13,262 8TB
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
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
r035198x
13,262 8TB
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
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

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

Similar topics

0
by: Neil Young | last post by:
Hello group, I'm referring to a "rather old thread" (April 21st 2005). Because I also ran into problems with ASP.NET 2.0 formview and DBNull, but found a way around, I would like to share my...
1
by: paulmac106 | last post by:
Hi, I have a gridview based on a SQL stored procedure. I then want to let the user filter the results by 4 textboxes. When all 4 textboxes have "some" search criteria the gridview works fine,...
0
by: Krish | last post by:
Hello, I have GridView and after binding data i can see cells empty only (empty row is created), but i checked database there is data available. I just started using GridView, trying to learn...
5
by: Mark Olbert | last post by:
I ran into a situation this morning where the RowUpdating event of a GridView kept insisting there were no entries in either the OldValues or NewValues dictionaries. The GridView is bound to a...
2
by: Anonieko | last post by:
Hello ASPNET guru's, What is a clean way to go around the problem of displaying a GridView templated column where data can contain Single Quote ( ' )? I maybe too naive, but this is of course...
1
by: Stu Lock | last post by:
Hi, I've spent the last hour trawling google for this - but all I find are people asking the same question! I have a gridview which is being databound to an empty datasource. I can display...
2
by: Bart | last post by:
Hi, i need to check wether a cell of a gridview is empty or not. I did this: Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
0
by: dhyder | last post by:
I'm working on an admin page for a SQL Server 05 db. The page is in ASP.NET 2.0/C#. The db has multiple tables with foreign keys/constraints. I have multiple SqlDataSources and GridViews, which...
2
by: joelkeepup | last post by:
Hi, I made a change this morning and now im getting an error that says either "a is undefined or null" or "e is undefined or null" the microsoft ajax line is below, I have no idea how to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.