Thursday, December 4, 2008

To create GridView with alternate rowcolor during mouseover and mouseout

Hi,
I want to create the GridView with Alternate RowBackColor when the
mouse is over.

This can be written in the
OnRowCreated="studGridView_RowCreated"
Event of GridView.

Code-Behind

string onmouseoverstyle = "this.style.backgroundColor='#f1f5e4'";
string onmouseoutstyle = "this.style.backgroundColor='@BackColor'";
string rowBackColor = String.Empty;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Alternate)
{
rowBackColor = System.Drawing.ColorTranslator.
ToHtml(sampleStudGridview.AlternatingRowStyle.BackColor).ToString();

}
else
{
rowBackColor = System.Drawing.ColorTranslator.
ToHtml(sampleStudGridview.AlternatingRowStyle.BackColor).ToString();

}
e.Row.Attributes.Add("onmouseover", onmouseoverstyle);
e.Row.Attributes.Add("onmouseout",onmouseoutstyle.
Replace("@BackColor",rowBackColor));

}

No comments: