programming.torensma.net: Code Snippets

CustomDataGrid (c#)

A DataGrid object with mouseover effects build in.

using System;

///
/// Summary description for CustomDataGrid.
///
public class CustomDataGrid
{
	public string ItemStyleMouseOver;
	public string AlternatingItemStyleMouseOver;

	public CustomDataGrid()
	{

	}

	protected override void OnItemCreated(DataGridItemEventArgs e)
	{

		if (e.Item.ItemType == ListItemType.Item)
		{
			e.Item.Attributes.Add(\"onmouseover\", \"this.className='\" + this.ItemStyleMouseOver + \"'\");
			e.Item.Attributes.Add(\"onmouseout\", \"this.className='\" + this.ItemStyle.CssClass + \"'\");
		}

		if (e.Item.ItemType == ListItemType.AlternatingItem)
		{
			e.Item.Attributes.Add(\"onmouseover\", \"this.className='\" + this.AlternatingItemStyleMouseOver + \"'\");
			e.Item.Attributes.Add(\"onmouseout\", \"this.className='\" + this.AlternatingItemStyle.CssClass + \"'\");
		}

		base.OnItemCreated (e);

	}
}

To use the CustomDataGrid in a page, include the following at the top of the page:


and insert this code where you want the control


				

You can follow any responses to this entry through the RSS 2.0 feed.