Background color in codebehind

  1. #1

    Background color in codebehind

    Hi !

    When setting a grid cell with the following: (passing this value to my store)

    "<p style=" + Chr(32) + "color: " + desiredColor + ";" + Chr(32) + ">" + desiredText + "</p>"
    The grid shows the desiredText with the font color I set.

    But how to setup the background color ?

    I´ve tried:

    "<p style=" + Chr(32) + "color: " + desiredColor + ";
    background-color:" +bkgColor + ";"+ Chr(32) + ">" + desiredText + "</p>"
    without success.

    Any help ?
  2. #2

    RE: Background color in codebehind

    Hi,

    You need define column renderer and set required css class which contains color and background-color definitions

    function myRenderer(value, meta, record) {
         meta.css = "myClass";
         return value;
    }
    
    . myClass{
    color: white !important;
            background-color:black !important;
    }
  3. #3

    RE: Background color in codebehind


    Sorry Vladsh,

    I forgot to mention in my thread above that I do it in code behind because it´s database bussines conditional formatation.

    Any clue ?
  4. #4

    RE: Background color in codebehind

    *Hi,

    you can dynamicaly build css rules with predefined names and then use these dynamic css rules in renderer


  5. #5

    RE: Background color in codebehind

    Thank´s !
  6. #6

    RE: Background color in codebehind

    Thank you very much, but could you please give me an example how do it ?
  7. #7

    RE: Background color in codebehind

    *I think i know what your getting at. *Been working on this for about 2 hours now. *Basically, I want to repaint a column background color when the data from that column exceeds 8. *I have this partially working based on Vlad's answer (by partially, i mean that it works on the cell but not the whole column).

    1) create a style element at the top of your page.
    **<style type="text/css">
    ** * * *.over-limit
    ** * * *{
    ** * * * * *background-color:LavenderBlush !important;
    ** * * *}
    ** * * *.under-limit
    ** * * *{
    ** * * * * *background-color:White !important;
    ** * * *}
    ** *</style>

    2) create a function in the javascript with teh following function signature as it will consume an event:
    *function myColOverlimit(value, meta, record) {
    ** *var foo = getColTlt(record.store, meta.id);
    ** *if (foo > 8) {
    ** * * *meta.css = "over-limit";
    ** *}
    ** *else {
    ** * * *meta.css = "under-limit";
    ** *}
    ** * * *return value;
    }

    3) create some functions that process the grid, in my case i tally up the 'Monday' column
    *function getColTlt(store, strCol) {
    ** *var iTotal = 0;
    ** *for (var i = 0; i < store.getCount(); i++) {
    ** * * *iTotal += parseFloat(store.getAt(i).get(strCol));
    ** *}
    ** *return iTotal;
    }*

    4) Wire this all up to the Grid through the Column Render:
    *<ext:Column ColumnID="Mon" *DataIndex="Mon" Header="Mon" Width="54">
    ** * * * * * * * * *<Editor>
    ** * * * * * * * * * * *<ext:TextField runat="server" ID="MonText">
    ** * * * * * * * * * * *</ext:TextField>
    ** * * * * * * * * *</Editor>
    ** * * * * * * * * *<Renderer Fn="myColOverlimit" />
    ** * * * * * * * * *
    ** * * * * * * *</ext:Column>



    hope this helps. *If anyone gets the column to change let me know ... ill post my solution when i figure it out.
  8. #8
    Hi I am in need of changing cell color of a TreeGrid depending on the value in the cell.
    I am dynamically binding the TreeGrid.
    How can I accomplish this task?
    Please help
    Last edited by rajputamit; Oct 28, 2010 at 9:54 AM.
  9. #9
    Hi,

    Please look at the example.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:TreeGrid runat="server" Width="310">
            <Columns>
                <ext:TreeGridColumn Header="task" DataIndex="test" Width="200" SortType="None" />
                <ext:TreeGridColumn Header="color" DataIndex="color" Width="100" SortType="None">
                    <XTemplate runat="server">
                        <Html>
                            <div style="background-color:{color}">{color}</div>
                        </Html>
                    </XTemplate>
                </ext:TreeGridColumn>
            </Columns>
            <Root>
                <ext:TreeNode Text="Tasks">
                    <Nodes>
                        <ext:TreeNode Leaf="true">
                            <CustomAttributes>
                                <ext:ConfigItem Name="test" Value="test1" Mode="Value" />
                                <ext:ConfigItem Name="color" Value="red" Mode="Value" />
                            </CustomAttributes>
                        </ext:TreeNode>
                        <ext:TreeNode Leaf="true">
                            <CustomAttributes>
                                <ext:ConfigItem Name="test" Value="test2" Mode="Value" />
                                <ext:ConfigItem Name="color" Value="green" Mode="Value" />
                            </CustomAttributes>
                        </ext:TreeNode>
                        <ext:TreeNode Leaf="true">
                            <CustomAttributes>
                                <ext:ConfigItem Name="test" Value="test3" Mode="Value" />
                                <ext:ConfigItem Name="color" Value="blue" Mode="Value" />
                            </CustomAttributes>
                        </ext:TreeNode>
                    </Nodes>
                </ext:TreeNode>
            </Root>
        </ext:TreeGrid>
        </form>
    </body>
    </html>

Similar Threads

  1. Replies: 2
    Last Post: Dec 29, 2011, 2:11 AM
  2. [CLOSED] How to set Panel background color?
    By wagger in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: May 14, 2011, 6:17 PM
  3. panel background color
    By unaltro2 in forum 1.x Help
    Replies: 2
    Last Post: Jan 10, 2011, 2:30 PM
  4. Set Viewport Background color or image
    By geodan in forum 1.x Help
    Replies: 4
    Last Post: May 28, 2010, 9:59 AM
  5. Change Tab background color or background image
    By georgelanes in forum 1.x Help
    Replies: 0
    Last Post: Nov 06, 2008, 3:55 PM

Posting Permissions