[CLOSED] How Can I do to get List of Store in CodeBehind

  1. #1

    [CLOSED] How Can I do to get List of Store in CodeBehind

    Hi How Can I do to get list of Store in Code Behind from a Click in DirectEvent of a Button:


            <ext:GridPanel
                ID="gpAlimentos"
                runat="server"
                Height="300"
                Width="802"
                Title="Alimentos">
                <TopBar>
                    <ext:Toolbar ID="tbTopAlimentos" runat="server">
                        <Items>
                            <ext:Button ID="btnGuardar" runat="server" Text="Save">
                                <DirectEvents>
                                    <Click OnEvent="btnGuardar_Click" />
                                </DirectEvents>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Store>
                    <ext:Store ID="sAlimentos" runat="server">
                        <Model>
                            <ext:Model ID="mAlimentos" runat="server">
                                <Fields>
                                    <ext:ModelField Name="ID" Type="Int" />
                                    <ext:ModelField Name="Grupo" Type="String" />
                                    <ext:ModelField Name="Nombre" Type="String" />
                                    <ext:ModelField Name="Marca" Type="String" />
                                    <ext:ModelField Name="Cantidad" Type="Int" />
                                    <ext:ModelField Name="UnidadMedida" Type="String" />
                                    <ext:ModelField Name="Precio" Type="Float" />
                                    <ext:ModelField Name="Lugar" Type="String" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel>
                    <Columns>
                        <ext:NumberColumn ID="ncID" runat="server" DataIndex="ID" Text="ID" />
                        <ext:Column ID="cGrupo" runat="server" DataIndex="Grupo" Text="Grupo">
                        </ext:Column>
                        <ext:Column ID="cNombre" runat="server" DataIndex="Nombre" Text="Nombre">
                        </ext:Column>
                        <ext:Column ID="cMarca" runat="server" DataIndex="Marca" Text="Marca">
                        </ext:Column>
                        <ext:NumberColumn ID="ncCantidad" runat="server" DataIndex="Cantidad" Text="Cantidad">
                        </ext:NumberColumn>
                        <ext:Column ID="cUnidadMedida" runat="server" DataIndex="UnidadMedida" Text="Unidad de medida" />
                        <ext:NumberColumn ID="ncPrecio" runat="server" DataIndex="Precio" Text="Precio" />
                        <ext:Column ID="cLugar" runat="server" DataIndex="Lugar" Text="Lugar" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
            protected void Page_Load(object sender, EventArgs e)
            {
                List<Alimentos> list = new List<Alimentos>(5);
    
                for (int i = 1; i <= 5; i++)
                {
                    Alimentos alimentos = new Alimentos
                    {
                        ID = i,
                        Grupo = ("Grupo" + i),
                        Nombre = ("Nombre" + i),
                        Marca = ("Marca" + i),
                        Cantidad = i,
                        UnidadMedida = ("UnidadMedida" + i),
                        Precio = Convert.ToDecimal(i * 85.12),
                        Lugar = ("Lugar" + i)
                    };
    
                    list.Add(alimentos);
                }
    
                sAlimentos.DataSource = list;
                sAlimentos.DataBind();
            }
    
            public class Alimentos
            {
                public int ID { get; set; }
                public string Grupo { get; set; }
                public string Nombre { get; set; }
                public string Marca { get; set; }
                public int Cantidad { get; set; }
                public string UnidadMedida { get; set; }
                public decimal Precio { get; set; }
                public string Lugar { get; set; }
            }
    
            protected void btnGuardar_Click(object sender, DirectEventArgs e)
            {
                //Here to get de List of object Alimentos from Store sAlimentos
                //List<Alimentos> lAlimentos = sAlimentos
            }
    Last edited by Daniil; Nov 05, 2013 at 8:37 AM. Reason: [CLOSED]
  2. #2
    Hello!

    Take a look at this example: https://examples2.ext.net/#/GridPane...itting_Values/

    Click OnEvent="SubmitSelection">
    	<ExtraParams>
    		<ext:Parameter Name="Values" Value="Ext.encode(#{GridPanel1}.getRowsValues({selectedOnly : true}))" Mode="Raw" />
    	</ExtraParams>
    </Click>
    This code sends values from the client but you don't need to use selected only, so it should be like this:

    Click OnEvent="SubmitSelection">
    	<ExtraParams>
    		<ext:Parameter Name="Values" Value="Ext.encode(#{GridPanel1}.getRowsValues())" Mode="Raw" />
    	</ExtraParams>
    </Click>
    And this code creates a list of your objects:

    string json = e.ExtraParams["Values"];
    
    List<Company> companies = JSON.Deserialize<List<Company>>(json);
    
    foreach (Company company in companies)
    {
    	string name = company.Name;
    	double price = company.Price;
    	double change = company.Change;
    	double pctChange = company.PctChange;
    
    	//handle values
    }
  3. #3
    Quote Originally Posted by Baidaly View Post
    Hello!

    Take a look at this example: https://examples2.ext.net/#/GridPane...itting_Values/

    Click OnEvent="SubmitSelection">
    	<ExtraParams>
    		<ext:Parameter Name="Values" Value="Ext.encode(#{GridPanel1}.getRowsValues({selectedOnly : true}))" Mode="Raw" />
    	</ExtraParams>
    </Click>
    This code sends values from the client but you don't need to use selected only, so it should be like this:

    Click OnEvent="SubmitSelection">
    	<ExtraParams>
    		<ext:Parameter Name="Values" Value="Ext.encode(#{GridPanel1}.getRowsValues())" Mode="Raw" />
    	</ExtraParams>
    </Click>
    And this code creates a list of your objects:

    string json = e.ExtraParams["Values"];
    
    List<Company> companies = JSON.Deserialize<List<Company>>(json);
    
    foreach (Company company in companies)
    {
    	string name = company.Name;
    	double price = company.Price;
    	double change = company.Change;
    	double pctChange = company.PctChange;
    
    	//handle values
    }
    Thank you Baidaly this is working and It is working with other ModelField that I not show in Gridpanel but my store is saved.

    <ext:ModelField Name="Campo" Type="String" />

    And, only to I know, There is other method but with properties of object "Store" in CodeBehind or Is this the only solution?
    Last edited by osef; Oct 30, 2013 at 9:41 PM.
  4. #4
    Quote Originally Posted by osef View Post
    And, only to I know, There is other method but with properties of object "Store" in CodeBehind or Is this the only solution?
    I'm not sure what do you mean. If I misunderstand you please elaborate your requirements. However, it's standard method to submit values from the Grid. Here is another sample using GenericHandler: https://examples2.ext.net/#/GridPane...it_to_Handler/

Similar Threads

  1. [CLOSED] Grid store bound to list
    By alexp in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Oct 12, 2012, 12:45 PM
  2. fill my store from a list of object.
    By DEV_EXT_TN in forum 2.x Help
    Replies: 0
    Last Post: Aug 01, 2012, 11:54 AM
  3. store charge from a list object
    By danilo in forum 1.x Help
    Replies: 1
    Last Post: Jul 08, 2011, 4:03 AM
  4. Store with List of String
    By jigpatel06 in forum 1.x Help
    Replies: 0
    Last Post: Apr 06, 2011, 3:05 PM
  5. [CLOSED] [1.0] List<> to Store?
    By state in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 29, 2009, 5:36 PM

Tags for this Thread

Posting Permissions