[CLOSED] Set color for ComboBoxFor items.

  1. #1

    [CLOSED] Set color for ComboBoxFor items.

    Hi
    Mine is a Asp.net MVC 4 (razor engine) application.
    I have a ComboBoxFor component in my form panel.
    as per values in the model
     var data= @Html.Raw(Json.Encode(Model.xyzList));
    i have to set color to the ComboBoxFor items.

    How to set color to the ComboBoxFor items?
    Last edited by Daniil; Sep 05, 2013 at 6:52 AM. Reason: [CLOSED]
  2. #2
    Hi @PriceRightHTML5team,

    I think you can achieve it using a ComboBox ListConfig's ItemTpl. Here is an example of using it.
    http://examples2.ext.net/#/Form/Comb...rop_Down_List/

    It makes sense for MVC as well.
  3. #3
    Hi Daniil

    following is my markup for comboboxfor
    X.ComboBoxFor(c => c.CsvTotalxyzList)
                                                .QueryMode(DataLoadMode.Local)                                            
                                                .Editable(false)
                                                .EmptyText(RP.ERRSelect).ID("Cmbxyz").Editable(false).Width(300)
                                                .Items(
                                                        from p in Model.xyzlist
                                                        select new Ext.Net.ListItem { Text = p.xyz_DESC, Value = p.xyz_CD.ToString() }
                                                      )
                                                .Listeners(l => { l.Select.Fn = "callRefreshView"; l.BoxReady.Fn = "ChangeColor"; l.DirtyChange.Fn = "SetDirty"; })
                                                .LabelCls("fieldLabelTop")
    How should i apply ListConfig's ItemTpl keeping the "Text" and "Value" feature intact, so as to get the selected listItem value in model and script as well.

    Kindly provide the appropriate markup.
  4. #4
    Quote Originally Posted by PriceRightHTML5team View Post
    How should i apply ListConfig's ItemTpl keeping the "Text" and "Value" feature intact, so as to get the selected listItem value in model and script as well.
    I am afraid I don't understand the question.

    I am posting here an example.

    Example
    @{
        var X = Html.X(); 
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>Ext.Net.MVC v2 Example</title>  
        
        <script>
            var getStyle = function (comboBox, item) {
                if (item.field1 === "2") {
                    return "color: green;";
                }
            };
        </script>
    </head>
    <body>
        @X.ResourceManager()
    
        @(X.ComboBox()
            .Items(
                X.ListItem().Text("Item 1").Value("1"),
                X.ListItem().Text("Item 2").Value("2"),
                X.ListItem().Text("Item 3").Value("3")
            )
            .ListConfig(X.BoundList()
                .ItemTpl(X.XTemplate()
                    .Html(@<text>
                        <div class="list-item" style="{[ getStyle(this, values) ]}">
                            {field2}
                        </div>
                    </text>)
                )
            )
        )
    
    </body>
    </html>
  5. #5
    Thanks Daniil

Similar Threads

  1. Html.X().ComboBoxFor bug
    By nurkmez in forum 2.x Help
    Replies: 3
    Last Post: Mar 26, 2013, 10:35 PM
  2. Replies: 5
    Last Post: Dec 07, 2012, 5:42 PM
  3. ComboBoxFor and empty value after load
    By zwf in forum 2.x Help
    Replies: 1
    Last Post: Nov 12, 2012, 2:46 PM
  4. Replies: 3
    Last Post: Nov 05, 2012, 12:51 PM
  5. [CLOSED] Color of gruptabpanel items text
    By Pablo_Azevedo in forum 1.x Premium Help
    Replies: 4
    Last Post: May 22, 2012, 3:13 PM

Posting Permissions