PDA

View Full Version : [CLOSED] Combo box set background color code behind



rbtceo
Nov 21, 2014, 5:53 AM
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.

Daniil
Nov 21, 2014, 10:24 AM
Hi @rbtceo,

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

rbtceo
Nov 23, 2014, 9:33 PM
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?

Daniil
Nov 24, 2014, 4:10 PM
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>

rbtceo
Nov 24, 2014, 9:42 PM
Daniil,

Your solution works fine.
Thank you.

The thread can be closed.

jcardenas
Apr 17, 2018, 4:47 PM
This not working in the new version.