Weird Thoughts From Eric's Head

Tags - Categories : All | AJAX | BUSINESS | PERSONAL | PROGRAMMING | BOOK REVIEW

Billable Hours Joke
A plumber attended to a leaking faucet at a neurosugeon's house. After a 2-minute job, he demanded $75.

"I don't charge this amount even though I'm a surgeon."

"You're right -- that's why I switched from surgery to plumbing!"

Entire Cell Clickable For Column Sort - ASP.NET
The one thing I love about datagrids is how easy you can make them sort your information. The thing I hate about the sort is you need to click the link to do it instead of the whole header cell. So I wrote up a little JavaScript function that makes the whole cell clickable for the sort! The following code needs to be placed between the head tags.

<script type="text/javascript">
  //Code Makes Entire Headers Clickable For Sorting
  function MakeHeadersClickable(xDataGridName){
    var theLinks = document.getElementById(xDataGridName).getElementsByTagName("a");  
//Grab all of the link elements
    var numLinks = parseInt(theLinks.length);
    for(i=0;i<numLinks;i++){  //Loop through the links
    theFunc = theLinks[i].href.split("pt:"); //Determine the post back code and remove the javascript: text
    if(theFunc.length > 1){
      theLinks[i].offsetParent.onclick = new Function(theFunc[1]); //Add the onclick event to the header
      //theLinks[i].className = "noUnde";                //Add CSS class to the link!
      theLinks[i].offsetParent.style.cursor = "pointer"; //Add Css pointer(hand) cursor to the header cell
    }
  }
</script>

You just need to call the code by adding an onload event handler to your body tag with the parameter of your datagrids name
  <body onload="MakeHeadersClickable('DataGrid1')">

Now when the page loads, the whole header column is made clickable! It is rather easy to do. If there is a way to do it without JavaScript someone please tell me.

Who is going to be the first Java person to complain about posting .NET stuff? LOL

Eric Pascarello
Moderator of HTML/JavaScript at www.JavaRanch.com
Author of: JavaScript: Your Visual Blueprint for Dynamic Web Pages


I added a post about making entore rows and cells clickable with JavaScript since many people seem to be coming here from google! link: Clickable Table Cells and Rows - JavaScript
Hi, Thanks a lot for the gr8 idea... It helped me out ... Keep posting interesting thinks Thanking u, Mitra


Add a comment

Title
Body
HTML : b, i, blockquote, br, p, pre, a href="", ul, ol, li
Math Quiz 4 + 6 = (Helps stop blog spam)
Name
E-mail address
Website
Remember me Yes  No 

E-mail addresses are not publicly displayed, so please only leave your e-mail address if you would like to be notified when new comments are added to this blog entry (you can opt-out later).

TrackBack to http://radio.javaranch.com/pascarello/addTrackBack.action?entry=1103294625000