Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting BackColor when using a skin file
Message
Information générale
Forum:
ASP.NET
Catégorie:
WebForms
Divers
Thread ID:
01306364
Message ID:
01308513
Vues:
12
>I'm creating a javascript function that highlights a row in a GridView when a checkbox in the row is checked. I'm trying to pass the normal row color into the javascript onClick call. I'm checking the e.Row.BackColor in the Row_DataBound event and adding an attribute to the CheckBox.
>
>The issue is that I'm using a skin file for the GridView and I'm getting "Color [Empty}" when for the BackColor. When do the settings from the skin file get applied? Or is their some way I can read the values for the row style and alternating row style from the skin file?
>
>In Row_DataBound after checking that it's a DataRow:
>
>string NormalRowColor = e.Row.BackColor.ToString();
>            CheckBox cb = (CheckBox)e.Row.FindControl("chkReq");
>            if (cb != null)
>            {
>
>                if (cb.Checked)
>                {
>                    e.Row.BackColor = System.Drawing.Color.LightGray;
>                }
>
>                string js = "javascript:colorRow(event," + NormalRowColor + ")";
>                cb.Attributes.Add("OnClick", js);
>            }
>
>
>
>Javascript
>
>function colorRow(e,normalColor)
>{
>// Annoying code to get the desired event handler from the browser.
>  if (!e) e = window.event;
>  var srcEl = e.target || e.srcElement;
>
>  var curElement = srcEl;
>  while (curElement && !(curElement.tagName == "TR"))
>  {
>    // Keep going until we reach the parent table row
>    curElement = curElement.parentNode;
>  }
>  if (curElement != srcEl)
>  {
>    if (srcEl.checked)
>    {
>    // Modify your colors here for a selected object
>      curElement.style.foregroundColor = "White";
>      curElement.style.backgroundColor = "#LightGrey";
>    }
>    else
>    {
>    // Modify your colors for a deselected object (read: Normal)
>      curElement.style.foregroundColor = "Black";
>      curElement.style.backgroundColor = normalColor;
>    }
>  }
>}
>
See http://www.gridviewguy.com/ArticleDetails.aspx?articleID=172
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform