Click here to Skip to main content
Click here to Skip to main content

How to click/select Row in ASP.NET GridView or HTML Table

By , 27 Jun 2012
 

The above code will slow down the browser and the browser can hang when Rows in Grid will be 10000 or above. Please view the below suggestion:

CS Code

protected void grvGroups_RowDataBound(object sender, GridViewRowEventArgs e)
{
 if (e.Row.RowType == DataControlRowType.DataRow)
  {
    e.Row.Attributes.Add("onclick", "setGridValue('" + e.Row.ClientID + "')");
  }
}

HTML Code

.sel
{
     color: #303030;
     font-size:3em;
     font-weight:bold;
     cursor:default;
}
.desel
{
     color: #909090;
     font-size:2em;
     font-weight:normal;
     cursor:pointer;
}

 

var oldro;
function setGridValue(ro)
{
 var rs=document.getElementById(ro);
 if(oldro!=null)
 {
  if(rs.className=="sel")
   return;
  oldro.className="desel";
 }
 rs.className="sel";
 oldro=rs;
}

And forget then loop.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Technoses
Software Developer (Senior) Super Eminent Softwares
India India
Member
Organisation
7 members

My name is Peeyush Shah and I am working with Microsoft.Net Framework at Jaipur, India with a Taxaction Software Development Company Named Professional Softec Pvt. Ltd.
 
My main focus is the development of online application.
We also develop custom software solutions for our customers and are able to support developers in using the following technologies, because we use them every day

- .NET Framework 2.0
- C#
- ASP.NET
- ASP.NET AJAX
- SQL Server 2005
- ADO .NET
- XML Webservices
- Payment systems

Feel free to take a look at the website and see Microsoft's new technologies in action

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralGreat!memberPritesh Aryan10 Dec '12 - 23:50 
thank you so much it helps me a lot Smile | :)
GeneralMy vote of 5membersanjeev kumar sharma Eng26 May '12 - 1:12 
well done
GeneralRe: Thank for your reply! Actually, I have changed all rs with _...memberbeginner201129 Jan '12 - 15:17 
Thank for your reply!
Actually, I have changed all rs with _row.
After checked again, I found the problem was I missed '' when setGridValue(" + e.Row.ClientID + ")".
Thanks for your tip!
GeneralIt didn't work. I have insert if(rs==null) alert("null") af...memberbeginner201118 Jan '12 - 20:21 
It didn't work.
I have insert if(rs==null) alert("null") after var _row = document.getElementById(ro)
It show message null.
GeneralRe: you r using var _row = document.getElementById(ro) and not ...groupTechnoses22 Jan '12 - 20:49 
you r using
var _row = document.getElementById(ro)
and not
var rs = document.getElementById(ro)
so rs is null
you should use rs in place of _row
or use _row in place of rs

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 27 Jun 2012
Article Copyright 2012 by Technoses
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid