Solved

Hilight a HTMLTable row when selected

Posted on 2013-06-03
6
234 Views
Last Modified: 2013-06-24
How can I Hilight a HTMLTable row when selected?   I know how to change the color, and I have code to find the row by ID, but how/where can I define handle a click event?   I want to do this in the codebehind

This code hilights a row:

           ctl = CType(Me.Page.FindControlRecursively("row"), HtmlTableRow)
            If Not IsNothing(ctl) Then

                 ' This will be used for each cell on the row.
                Dim recordRowCell As System.Web.UI.HtmlControls.HtmlTableCell

                ' Set the background color on the record row in RGB format.
                Dim color As String = "#fff000"

                ' For each cell, set the background color.
                For Each recordRowCell In ctl.Cells

                    ' Override the record row background color -- since each data cell uses a
                    ' style (by default: table_cell or table_cellr)
                    recordRowCell.Style.Add("background-color", color)

                Next

            End If
0
Comment
Question by:HLRosenberger
  • 3
  • 2
6 Comments
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 39217635
You do not need code behind use css to add mouse hover effect on each row as follows:
.mytable tr:hover,  selectedrow
{ 
  background-color: #632a2a;
  color: #fff;
}  

Open in new window


I assume your table markup is like:
<table class="mytable">
          <tr>
                   Your table contents goes here
          </tr>
</table>

Open in new window

Note: Class mytable is only used to identify which table requires the css rule.

I f you need to do this when user clicks the row, you can add Javascript onclick event and define a method  that remove the class selectedrow from the selected row markup and added to the current row defined by the click event. Let me know if you want to go that path to provide the code and if you are using jquery. (VS2010 and VS2012 add this JS library by default to web projects)
0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 39226751
I do not want the change on hover over.  I want to change the color on click.  Yes, please provide the javascript for this.  Thanks!
0
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 39233686
OK, this method in Jquery setup all click event on cells as follows:
function SetupClientClick() {
$("TD").click(function() {
  $(this).closest("tr").siblings().removeClass("selectedrow");
  $(this).parents("tr").toggleClass("selectedrow", this.clicked);
});
};

Open in new window

where
.selectedrow
{ 
  background-color: #632a2a;
  color: #fff;
} 

Open in new window

You can call it once your document is ready or as a startup script (see example first link)

For further info, check:
http://api.jquery.com/click/
http://stackoverflow.com/questions/1287699/jquery-highlight-de-highlight-table-row-on-click
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 25

Expert Comment

by:Rouchie
ID: 39238086
I wrote this today, is it what you're looking for?  Client-side click?
http://www.codepal.co.uk/show/Highlight_a_Gridview_table_row_on_selection_using_JQuery
0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 39248900
I do not know jQuery.
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 39271347
thanks,.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now