Thanks for Jon's good suggestions.
Hi Brian,
I think Jon's idea is pretty good and as for webform datagrid, the "<tr>"
should mapping to the DAtaGridItem class and we can reference it and set
the "onmouseover" and "onmouseout" attribute for it. And I suggest that you
set the attributes in the DataGrid's "ItemCreated" event. Here is a simple
demo page, you may have a look :
===============aspx ================
<HTML>
<HEAD>
<title>mouseeffect</title>
<style>
TR.off { BACKGROUND-COLOR: white }
TR.on { BACKGROUND-COLOR: yellow }
</style>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td>
<asp
ataGrid id="dgStyle" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Column1"
HeaderText="Column1"></asp:BoundColumn>
<asp:BoundColumn DataField="Column2"
HeaderText="Column2"></asp:BoundColumn>
<asp:BoundColumn DataField="Column3"
HeaderText="Column3"></asp:BoundColumn>
</Columns>
</asp
ataGrid>
</td>
</tr>
</table>
</form>
</body>
</HTML>
========code behind=================
public class mouseeffect : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgStyle;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
Bind_Data();
}
}
private void Bind_Data()
{
DataTable dt = new DataTable("dt");
dt.Columns.Add("Column1",typeof(string));
dt.Columns.Add("Column2",typeof(string));
dt.Columns.Add("Column3",typeof(string));
for(int i=0;i<5;i++)
{
DataRow row = dt.NewRow();
row[0] = "Column1Value"+ i;
row[1] = "Column2Value"+ i;
row[2] = "Column3Value"+ i;
dt.Rows.Add(row);
}
dgStyle.DataSource = dt;
dgStyle.DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.dgStyle.ItemCreated += new
System.Web.UI.WebControls.DataGridItemEventHandler(this.dgStyle_ItemCreated)
;
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void dgStyle_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover","this.className='on'");
e.Item.Attributes.Add("onmouseout","this.className='off'");
}
}
}
=======================================
Hope also helps. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)