[CLOSED] Fill a combobox with an enum.

  1. #1

    [CLOSED] Fill a combobox with an enum.

    Hi all,
    which is the best way to fill a combobox with an enum.
    For example, how do i define the store reader for an enum?!

    It will also great to add this to the examples.

    Moreover i have like:
        public enum Data
        {
            First,
            Second,
            Third,
            Fourth
        }
    But i want to display One, Two, Three, Four.
  2. #2
    Hi,

    Please see the following sample
    <%@ 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 id="Head2" runat="server">
        <title>TreeGrid - Ext.NET Examples</title>
        
        <script runat="server">
            public enum Data
            {
                First,
                Second,
                Third,
                Fourth
            }
            
            protected void Page_Load(object sender, EventArgs e)
            {
                foreach (string item in Enum.GetNames(typeof(Data)))
                {
                    Combo1.Items.Add(new Ext.Net.ListItem(item));
                }
            }
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            
            <ext:ComboBox ID="Combo1" runat="server" />
        </form>
    </body>
    </html>
  3. #3
    Thanks, more easy than i was thinking.

    You didn't answer on the "First" => "One" conversion.
    You suggest to use a template to have a custom render?
  4. #4
    Hi,

    You can convert it at server side
    Combo1.Items.Add(new Ext.Net.ListItem(item == "First" ? "One" : item));
  5. #5
    I just saw that the ListItem has a constructor that accepts a Text and a Value.
    Thanks ;)

Similar Threads

  1. Fill Calendar Panel on combobox selection
    By Rupesh in forum 1.x Help
    Replies: 7
    Last Post: Mar 29, 2012, 2:14 PM
  2. Problem to fill a combobox with store
    By feanor91 in forum 1.x Help
    Replies: 1
    Last Post: Nov 22, 2011, 1:12 PM
  3. [CLOSED] Fill a store with an enum
    By 78fede78 in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Nov 10, 2010, 4:50 PM
  4. combobox fill dynamically uing enum
    By Prasad in forum 1.x Help
    Replies: 0
    Last Post: Aug 19, 2010, 12:29 PM
  5. Replies: 1
    Last Post: Jul 02, 2010, 1:08 AM

Tags for this Thread

Posting Permissions