Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
245
Changing Grid Cell Background and Text Color in RowInitialize
posted

Having an issue with setting the background and text color of an individual cell in a row based on the value in another column of the row.

Here's the code:

Private Sub TabsGrid_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.Web.UI.GridControls.RowEventArgs) Handles TabsGrid.InitializeRow

 ' Get the cell and color from the grid

 Dim ColorCell As Infragistics.Web.UI.GridControls.GridRecordItem = e.Row.Items.FindItemByKey("tabcolor")
 Dim ColorInteger As Integer = CInt(e.Row.Items.FindItemByKey("tab_color").Value)

 ' Now set the color to RGB format

 Dim Color As Color = Functions.BgrToRgb(ColorInteger)
 Dim HexColor As String = Functions.HexFromRGB(Color.R, Color.G, Color.B)

 ' Now set the fore and back color of the cell and populate it

 ColorCell.CssClass = Infragistics.Web.UI.Framework.AppStyling.AppStylingManager.Settings.CssRegistry.Add("color: " & HexColor & "; background-color: " & HexColor, "")
 ColorCell.Text = HexColor

End Sub

When the code runs, the background neither the text color or background color is being changed. Is there another way to accomplish this with server side events?

Here's the column definition, not sure if using an unbound field is the right one to use to be able to change the background color:

<Columns>
 <igtbl:BoundDataField Header-Text="Tab" Key="tab_no" Header-Tooltip="Tab" DataFieldName="tab_no" />
 <igtbl:BoundDataField Header-Text="Description" Key="description" Header-Tooltip="Description" DataFieldName="description" />
 <igtbl:BoundDataField Header-Text="Page" Key="doc_page" Header-Tooltip="Page" DataFieldName="doc_page" />
 <igtbl:UnboundField Header-Text="Color" Key="tabcolor" Header-Tooltip="Color" />
 <igtbl:BoundDataField Header-Text="" Key="tab_color" Header-Tooltip="" Hidden="true" DataFieldName="tab_color" />                                                                               
</Columns>