10/31/2011

Gridview RowDataBound Mouse Events

This is just an example code.

.aspx page

<asp:GridView ID="grdMouseEvents" runat="server" OnRowDataBound = "grdMouseEvents_RowDataBound">
>
<asp:BoundField HeaderText="Firstname" />
<asp:BoundField HeaderText="Lastname" />
Columns>
asp:GridView>


.aspx.cs page (C#.net)

protected void grdMouseEvents_RowDataBound(object sender, GridViewRowEventArgs e)
{

if(e.Row.RowType == DataControlRowType.DataRow)
{

string onmouseoverStyle = "this.style.backgroundColor='#CCCCCC'";

string onmousedownStyle = "this.style.backgroundColor='#66CCFF'";

string onmouseoutStyle = "this.style.backgroundColor='#FFFFFF'";

if (e.Row.RowType == DataControlRowType.DataRow)

{

e.Row.Attributes.Add("onmouseover", onmouseoverStyle);

e.Row.Attributes.Add("onmousedown", onmousedownStyle);

e.Row.Attributes.Add("onmouseout", onmouseoutStyle);

}
}
}

Si Sii

No comments:

Post a Comment