[CLOSED] Combo box set background color code behind

  1. #1

    [CLOSED] Combo box set background color code behind

    Hi All,

    There is a method (code behind):
    comboBox.SetVaue(value);
    I need to set a background color as well.
    How can I set background color at the same time as the value?

    Thank you.
    Last edited by Daniil; Nov 24, 2014 at 11:07 PM. Reason: [CLOSED]
  2. #2
    Hi @rbtceo,

    This thread might help you.
    http://forums.ext.net/showthread.php?46871
  3. #3
    Daniil,

    Thank you for your answer.
    I saw that thread and it provides a client side solution. (if it is not, please, make it clear for me)

    Can I change a color in code-behind?
  4. #4
    Yes, it is a client side solution and there is no a direct code behind counterpart for that.

    I can suggest this solution.

    Example
    <%@ Page Language="C#" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.ComboBox1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "1", "Item 1" },
                    new object[] { "2", "Item 2" },
                    new object[] { "3", "Item 3" }
                };
            }
        }
    
        protected void SetYellow(object sender, DirectEventArgs e)
        {
            X.Js.Call("setBackgroundColor", new JRawValue(this.ComboBox1.ClientID), "yellow");
        }
    
        protected void SetGreen(object sender, DirectEventArgs e)
        {
            X.Js.Call("setBackgroundColor", new JRawValue(this.ComboBox1.ClientID), "green");
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    
        <script>
            var setBackgroundColor = function (comboBox, color) {
                comboBox.inputEl.setStyle({
                  "background-image": "none",
                  "background-color": color
                });
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:Button runat="server" Text="Set yellow" OnDirectClick="SetYellow" />
    
            <ext:Button runat="server" Text="Set green" OnDirectClick="SetGreen" />
    
            <ext:ComboBox 
                ID="ComboBox1" 
                runat="server" 
                DisplayField="text" 
                ValueField="value">
                <Store>
                    <ext:Store runat="server">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="value" />
                                    <ext:ModelField Name="text" />
                                </Fields>
                            </ext:Model>
                        </Model>
                        <Reader>
                            <ext:ArrayReader />
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:ComboBox>
        </form>
    </body>
    </html>
  5. #5
    Daniil,

    Your solution works fine.
    Thank you.

    The thread can be closed.
  6. #6

    4.5.1

    This not working in the new version.
    Last edited by jcardenas; Apr 17, 2018 at 5:48 PM. Reason: Wrong version.

Similar Threads

  1. Replies: 2
    Last Post: Mar 06, 2014, 11:38 AM
  2. [CLOSED] ButtonGroup background-color IE7/IE8
    By cwolcott in forum 2.x Premium Help
    Replies: 2
    Last Post: Mar 07, 2013, 11:49 AM
  3. Replies: 5
    Last Post: Dec 07, 2012, 5:42 PM
  4. panel background color
    By unaltro2 in forum 1.x Help
    Replies: 2
    Last Post: Jan 10, 2011, 3:30 PM
  5. Change Tab background color or background image
    By georgelanes in forum 1.x Help
    Replies: 0
    Last Post: Nov 06, 2008, 4:55 PM

Tags for this Thread

Posting Permissions