Highlighting Rows in an ASP.NET DATAGRID ...
By: John Kilgo Date: January 11, 2003 Download the Code.
Printer Friendly Version
I like the idea of highlighting rows in a DataGrid as the user scrolls the mouse up and down over the grid. The effect can be achieved using several lines of client-side JavaScript, but why do that when two lines of .Net code will accomplish the same thing? The trick is to implement an ItemDataBound event handler and add OnMouseOver and OnMouseOut attributes to handle the color change. The code for this project is in two parts. An aspx page is used to define the datagrid and its attributes, while a .vb code-behind page is used to implement the database activity and handle the ItemDataBound method. First the .aspx page. Notice the line OnItemDataBound = "dtgCustomers_ItemDataBound". OnItemDataBound is a DataGrid method that raises the ItemDataBound event. "dtgCustomers_ItemDataBound" is the Event Handler Which is Contained in the code: i Chose to Display Rows from the Northwind Customers Table. Since this Table Contains over 90 Rows, I Also Implement Paging For th E DataGrid. if You Have Used DataGrids At All The rest of the attributes shouth be self evlantory. I Won't spend any more time on the .aspx page.
<% @ Page language = "vb" src = "highlightdatagrid.aspx.vb" inherits = "highlightdataGrid"%>