GridView gv = (GridView)sender string NormalRowColor = ""; if (e.Row.RowState == DataControlRowState.Alternate) NormalRowColor = System.Drawing.ColorTranslator.ToHtml(gv.AlternatingRowStyle.BackColor); else NormalRowColor = System.Drawing.ColorTranslator.ToHtml(gv.RowStyle.BackColor);>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.
>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); > } > >>
>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; > } > } >} >