?
Solved

Hilight a HTMLTable row when selected

Posted on 2013-06-03
6
Medium Priority
?
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 36

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 36

Accepted Solution

by:
Miguel Oz earned 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

762 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