Click here to Skip to main content
15,878,814 members
Articles / Web Development / HTML5
Alternative
Tip/Trick

Click/select Row in ASP.NET GridView or HTML Table

Rate me:
Please Sign up or sign in to vote.
4.20/5 (5 votes)
28 Dec 2011CPOL 18.8K   4   7
Following are optimized code for SelectRow functionStylesheet.selectedRow{color: #303030;font-size:3em;font-weight:bold;}.normalRow{color: #909090;font-size:2em;font-weight:normal;}Javascriptfunction SelectRow(row) { // get all data rows - siblings to...
Following are optimized code for SelectRow function

Stylesheet
CSS
.selectedRow
{
color: #303030;
font-size:3em;
font-weight:bold;
}
.normalRow
{
color: #909090;
font-size:2em;
font-weight:normal;
}


Javascript
JavaScript
function SelectRow(row) {
  // get all data rows - siblings to current
  var _rows = row.parentNode.childNodes;
  // deselect all data rows
  try {
     for (i = 0; i < _rows.length; i++) {
     _rows[i].getElementsByTagName("td")[0].className='normalRow';
      }
  }
  catch (e) { }
  // select current row (formatting applied to first cell)
row.getElementsByTagName("td")[0].className='selectedRow';
  }


Thanks,
Imdadhusen

License

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


Written By
Technical Lead Infostretch Ahmedabad-Gujarat
India India
Aspiring for a challenging carrier wherein I can learn, grow, expand and share my existing knowledge in meaningful and coherent way.

sunaSaRa Imdadhusen


AWARDS:

  1. 2nd Best Mobile Article of January 2015
  2. 3rd Best Web Dev Article of May 2014
  3. 2nd Best Asp.Net article of MAY 2011
  4. 1st Best Asp.Net article of SEP 2010


Read More Articles...

Comments and Discussions

 
GeneralReason for my vote of 1 loop is the problem if rows will 100... Pin
Technoses30-Dec-11 18:43
Technoses30-Dec-11 18:43 
GeneralRe: Reason for my vote of 1loop is the problem if rows will 100... Pin
Sunasara Imdadhusen22-Apr-14 4:04
professionalSunasara Imdadhusen22-Apr-14 4:04 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.