PDA

View Full Version : [CLOSED] How Can I do to get List of Store in CodeBehind



osef
Oct 30, 2013, 8:22 PM
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
}

Baidaly
Oct 30, 2013, 9:08 PM
Hello!

Take a look at this example: http://examples2.ext.net/#/GridPanel/Selection_Models/Submitting_Values/


Click OnEvent="SubmitSelection">
<ExtraParams>
<ext:Parameter Name="Values" Value="Ext.encode(#{GridPanel1}.getRowsValues({selectedOn ly : 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
}

osef
Oct 30, 2013, 10:37 PM
Hello!

Take a look at this example: http://examples2.ext.net/#/GridPanel/Selection_Models/Submitting_Values/


Click OnEvent="SubmitSelection">
<ExtraParams>
<ext:Parameter Name="Values" Value="Ext.encode(#{GridPanel1}.getRowsValues({selectedOn ly : 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?

Baidaly
Oct 30, 2013, 11:43 PM
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: http://examples2.ext.net/#/GridPanel/Miscellaneous/Submit_to_Handler/