[CLOSED] Add record server side to dynamically generated store

  1. #1

    [CLOSED] Add record server side to dynamically generated store

    Hi, I have a store that where I define the columns on the server side.
    I'd like to also be able to add records to this store.
    But the only method I see is store.AddRecord(object values).

    I'm getting the data for this record from various sources, and I know what the columns names are...how can I create a string of JSON, then convert that to an object so I can pass to this method?
    Last edited by Daniil; Aug 08, 2011 at 1:24 PM. Reason: [CLOSED]
  2. #2
    Hi,

    .AddRecord() method expects the same object which you data bind to a store.

    Here is an example.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        public List<object> MyData = new List<object> 
        { 
            new 
            { 
                test1 = "test1",
                test2 = "test2"
            },
            new 
            { 
                test1 = "test3",
                test2 = "test4"
            },
            
        };
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.Store1.DataSource = MyData;
                this.Store1.DataBind();
            }
        }
    
        protected void AddRecord(object sender, DirectEventArgs e)
        {
            object newRecord = new
            {
                test1 = "test5",
                test2 = "test6"
            };
            this.Store1.AddRecord(newRecord);
        }
    </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 runat="server" AutoHeight="true">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Reader>
                            <ext:JsonReader>
                                <Fields>
                                    <ext:RecordField Name="test1" />
                                    <ext:RecordField Name="test2" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column Header="Test1" DataIndex="test1" />
                        <ext:Column Header="Test2" DataIndex="test2" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
            <ext:Button runat="server" Text="Add a new record" OnDirectClick="AddRecord" />
        </form>
    </body>
    </html>

Similar Threads

  1. Replies: 3
    Last Post: Dec 26, 2011, 1:32 PM
  2. Replies: 1
    Last Post: Dec 01, 2010, 5:14 PM
  3. Replies: 0
    Last Post: Nov 17, 2010, 9:32 PM
  4. Replies: 1
    Last Post: Aug 12, 2010, 5:07 PM
  5. [CLOSED] CheckboxGroup load dynamically in server side
    By majestic in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 06, 2009, 9:41 AM

Posting Permissions