ASP.net CSS for GridView

Murray Brown
Murray Brown used Ask the Experts™
on
Hi

I want to add a bit of CSS code in my ASP.net site that will liven up my GridView.
For instance I would like the background color to change when the user's mouse hovers a row.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chief Technology Ninja
Distinguished Expert 2018
Commented:
Hi Murray,

You can use: https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.datagrid.itemdatabound?view=netframework-4.7.2

public void Item_Bound(object sender, DataGridItemEventArgs e)
{
  if (e.Item.ItemType.equals(ItemType.Item))
  {
    ((DataRowView)e.Item.DataItem).Row.Attributes.Add("onmouseover","this.style.backgroundColor='AliceBlue'");
    ((DataRowView)e.Item.DataItem).Row.Attributes.Add("onmouseout","this.style.backgroundColor='White'");
  }

Open in new window


Regards,
Chinmay.
Murray BrownASP.net/VSTO Developer

Author

Commented:
Great answer! Thanks very much

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial