Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Referring to the object as this
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Referring to the object as this
Environment versions
Environment:
C# 2.0
OS:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01308809
Message ID:
01308809
Views:
53
Hi everybody,

I wish I payed more attention to the recent thread about accessing object's name with this in C#.

I have the following code:
 protected void grdDeleteUsers_RowCreated(object sender, GridViewRowEventArgs e)
         {
             //Colors charts - see http://www.1netcentral.com/color-chart.html
             string onmouseoverStyle = "this.style.backgroundColor='00BFFF'"; // Deepskyblue

            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(grdDeleteUsers.AlternatingRowStyle.BackColor).ToString();

                else rowBackColor = System.Drawing.ColorTranslator.ToHtml(grdDeleteUsers.RowStyle.BackColor).ToString();

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

                e.Row.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", rowBackColor));

            }
        }
I want to make it generic, so I can easily add highligting to my grids. Note, that in my current implementation I specify grid's name.

Do you know how can I make this more generic - function in the page, method, etc.?

What would you suggest?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Next
Reply
Map
View

Click here to load this message in the networking platform