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