Click here to Skip to main content
16,018,458 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,

How to highlight datalist item on mouseover using Asp.Net C#.
I see an article specifying it. but it's not working..

http://www.dotnetfox.com/articles/how-to-highlight-datalist-item-on-mouseover-using-Asp-Net-with-C-Sharp-1040.aspx#[^]

How can I solve it.

Please help me..

Thanks in advance,

Vineetha
Posted
Comments
Richard Deeming 24-Jul-14 14:19pm    
Define "not working".

All you need to do is set a CSS class on each item, and then use the .classname:hover pseudo-class to set the style you want when the mouse is over the item.

C#
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
   {
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
           e.Row.Attributes.Add("onmouseover", "this.className='highlight'");
           e.Row.Attributes.Add("onmouseout", "this.className='normal'");
       }
   }
 
Share this answer
 
1) Create a css class and define the color we want to use for highlighting in html source of page

ex: For Highlight Grid- highlightGridrow

For Normal Grid- normalGridrow

2)Add onmouseover and onmouseout attributes to gridview rows in RowCreated event in code behind


protected void dgvTest_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.className='highlightGridrow'");
e.Row.Attributes.Add("onmouseout", "this.className='normalGridrow'");
}
}


Or Simply Use

.GridViewCssName:hover{style Attributes}

.Grid:hover { color: #000; text-decoration: none; }

Santhosh
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900