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>
Sometimes simple is better. This worked for me.
Dim FreeSpace As DoubleFor Each r As Infragistics.Web.UI.GridControls.GridRecord In DiskSpaceWebDataGrid.Rows Dim FreeSpaceCell As Infragistics.Web.UI.GridControls.GridRecordItem = r.Items.FindItemByKey("FreeSpace") FreeSpace = FreeSpaceCell.Value If FreeSpace < 8 Then FreeSpaceCell.Text = "<font color=red>" & FreeSpaceCell.Text & "</font>" End If Next
Was able to get around the issue with putting a panel inside the grid and setting the background color of the panel and that worked
This will not likely work for our scenario since we can't create CSS classes for every background color a user can choose.
Is there a likely chance that Infragistics is going to allow the background color to be modified outside of using CSS classes?
Hello Quan,
Thank you for your patience and explanation.
The correct way of handling this is by adding CSS classes to the cells.
You could dynamically add styles to the page from the code-behind.
I am attaching a sample demonstrating this approach.
Please let me know if you need anything else.
Thanks Denis,
Unfortunately setting the background color client-side isn't an option as we have some server-side code to process data and set the tabs as we aren't hard coding the background color, it's being pulled dynamically from a database entry.