[CLOSED] Fill a store with an enum

  1. #1

    [CLOSED] Fill a store with an enum

    Hi

    I did not find examples on this topic.
    Last edited by geoffrey.mcgill; Nov 10, 2010 at 5:40 PM. Reason: [CLOSED]
  2. #2
    Probably just need to convert the Enum to a List, then bind to the DataSource of the Store.

    I believe there is a .ToList() option if you include the LINQ assemblies.

    Hope this helps.
    Geoffrey McGill
    Founder
  3. #3
    Hi,

    Please see the following sample
    <%@ Page Language="C#" %>
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    <%@ Import Namespace="System.Linq" %>
    
    <!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="Head1" runat="server">
        <title></title>
        
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                Store1.DataSource = Enum.GetNames(typeof(Icon)).ToList().ConvertAll<object>(str => new { Icon = str });
                Store1.DataBind();
            }
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
             
            <ext:Store ID="Store1" runat="server">
                <Reader>
                    <ext:JsonReader>
                        <Fields>
                            <ext:RecordField Name="Icon" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
        </form>
    </body>
    </html>
  4. #4
    ok but for this example are missing values.

    Enum.GetValues
  5. #5
    Hi,

    With values it can look something like this. (I'm not sure maybe there is some way to convert more effective).

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Import Namespace="System.Linq" %>
    
    <script runat="server">
        enum TestEnum
        {
            Test1 = 1,
            Test2 = 10,
            Test3 = 255
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                var list = Enum.GetNames(typeof(TestEnum)).ToList().ConvertAll<TestClass>(str => new TestClass { Name = str });
                
                var values = Enum.GetValues(typeof(TestEnum));
                int i = 0;
                list.ForEach(delegate(TestClass test) 
                {
                    test.Value = ((int)values.GetValue(i++)).ToString();  
                });
    
                store.DataSource = list;
                store.DataBind();
            }
        }
    
        class TestClass
        {
            public string Name { get; set; }
            public string Value { get; set; }
        }
    </script>
    
    <!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:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <Reader>
                        <ext:JsonReader>
                            <Fields>
                                <ext:RecordField Name="Name" />
                                <ext:RecordField Name="Value" />
                            </Fields>
                        </ext:JsonReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Header="Names" DataIndex="Name" />
                    <ext:Column Header="Values" DataIndex="Value" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
        </form>
    </body>
    </html>
  6. #6
    This really is not an Ext.NET related issue.

    You just need to convert whatever it is to a List, then bind to the Store.

    Marking thread a [CLOSED].
    Geoffrey McGill
    Founder

Similar Threads

  1. [CLOSED] Store and enum bindings
    By digitek in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Aug 01, 2012, 9:44 AM
  2. [CLOSED] Fill a combobox with an enum.
    By capecod in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Oct 22, 2010, 2:06 PM
  3. combobox fill dynamically uing enum
    By Prasad in forum 1.x Help
    Replies: 0
    Last Post: Aug 19, 2010, 12:29 PM
  4. Enum in Store
    By EzaBlade in forum 1.x Help
    Replies: 0
    Last Post: Jul 07, 2009, 7:03 PM
  5. Coolite 0.7 + Enum support in Store
    By echo in forum Open Discussions
    Replies: 1
    Last Post: Dec 16, 2008, 5:10 AM

Tags for this Thread

Posting Permissions