Solved

Hilight a HTMLTable row when selected

Posted on 2013-06-03
6
238 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

707 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