.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Gridview and Javascript problem

Posted By: pooja     Posted Date: March 25, 2010    Points:2   Category :ASP.Net
Hi frnds ,,,,

i have a gridview which has 4 columns and i used checkboxes as the first column of the gridview for selecting all rows or selecting a particular...


for checkboxes selecting and unselecting i used javascript validation like following





JAVASCRIPT CODE :




function Check(rowcheckname)
{
var i=2;
var c=2;
var u=2;
var ckbox;
var gvmail=document.getElementById ('<%= gvMail.ClientID%>');
ckbox=document.getElementById (gvmail.id + '_ctl0' + i + "_" + rowcheckname);
while(ckbox!=null)
{
if(ckbox.Checked==true)
{
c=c+1;
}
else
{
u=u+1;
}
i=i+1;
ckbox=document.getElementById (gvmail.id + '_ctl0' + i + "_" + rowcheckname);
}
ckbox=document.getElementById (gvmail.id+'_ctl01chkAll'+i+"_"+rowcheckname );
if(i==c)
{
ckbox.Checked=true;

}
if(i=u)
{ckbox.Checked=false;}
if(i!=c)
{ckbox.Checked=false;}

}


function SelOrUnselAll(obj,rowcheckboxname)
{
var gridname=document.getElementById ('<%=gvMail.ClientID %>');
if(obj.Checked==true)
{
SelectAll(gridname,rowcheckboxname);
}
else
{
UnselectAll(gridname,rowcheckboxname);
}
}


function SelectAll(GridName,rowcheckboxname)
{
var chkbox;
var i=2;
chkbox =document.getElementById (GridName.id + "_ctl0" + i +"_" + rowcheckboxname);
while(chkbox!=null)
{
chkbox.Checked=true;
i=i+1;
chkbox =document.getElementById (GridName.id + "_ctl0" + i +"_" + rowcheckboxname);
}

}

function UnselectAll(GridName,rowcheckboxname)
{
var chkbox;
var i=2;
chkbox =document.getElementById (GridName.id + "_ctl0" + i +"_" + rowcheckboxname);
while(chkbox!=null)
{
chkbox.Checked=false;
i=i+1;
chkbox =document.getElementById (GridName.id + "_ctl0" + i +"_" + rowcheckboxname);
}

}





the above fuctions are called from checkbox events like fowwowing


<asp:CheckBox id="chekAll" runat="server" OnClick="SelOrUnselAll(this,'this.cheRow')" />



<asp:CheckBox ID="cheRow" runat="server" OnClick="Check(this.cheRow)" />






Error am getting is :

"Microsoft JScript runtime error: 'null' is null or not an object"



in the following lines in the above code

if(i==c)
{
ckbox.Checked=true;

}





plase help me in debugging this..............

Responses
Author: Amit Mehra             
Posted Date: March 25, 2010     Points: 5   

Hi,

you can use Jquery to check all functionality with less lines of code

function checkAll(isChecked) {
$(".ApprovalCheckBox > input").each(function() {
this.checked = isChecked;
});
}

More details can be found here

http://elegantcode.com/2007/12/27/check-all-with-jquery-and-a-aspnet-gridview/

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Lalij Mer             
Posted Date: March 26, 2010     Points: 5   

Check here you will get your solutions

http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=77491

Please Check my answer if you help....
Thank You...

Lalit.


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend