[CLOSED] Insert records in a gridpanel from codebehind

  1. #1

    [CLOSED] Insert records in a gridpanel from codebehind

    I can insert records in the gridpanel, each record inserted sent it directly to the database.
    But now I want to insert records, without storing them in the database, to the end, for example:

    Click image for larger version. 

Name:	Captura.JPG 
Views:	161 
Size:	24.2 KB 
ID:	5552

    By clicking "Agregar Paso" shows the following:

    Click image for larger version. 

Name:	Captura2.JPG 
Views:	144 
Size:	26.9 KB 
ID:	5553

    By clicking on the "Agregar" button, you should insert a new record in the gridpanel with the data shown in the window, but do not insert it into the database.

    I do so with the following code:

    Dim datos As New List(Of Object)()
         datos.Add(New With { _
                    Key .ProcRecPasos = Date.Now.TimeOfDay.ToString, _
                     .Nombre = "Paso uno de prueba", _
                     .Peso = 2, _
                     .Obligatorio = True, _
                     .Duracion = 10, _
                     .Porcentaje = Porcentaje, _
                     .TipoCalificacion = "N", _
                     .EnviaAlerta = True, _
                     .JefeInmediato = False, _
                     .Solicitante = True, _
                     .UsuarioEspec = False _
                    } _
                )
                    
                    StoreProcRecPasos.DataSource = Datos            
                    StoreProcRecPasos.DataBind()
    but only inserts a record, no more, because I do not know how to accumulate records in the variable "datos"

    How could I solve this problem?

    thanks!
    Last edited by Baidaly; Feb 06, 2013 at 10:53 PM. Reason: [CLOSED]
  2. #2
    Hello!

    To add new record you can use Store.Add method; Please, take a look at the following example:

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void InsertRecord(object sender, DirectEventArgs e)
        {
            Store1.Add(new { company = "MyCo", price = 71.72, change = 0.02, pctChange = 0.03, lastChange = DateTime.Now });
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.BindData();
            }
        }
    
        protected void MyData_Refresh(object sender, StoreReadDataEventArgs e)
        {
            this.BindData();
        }
    
        private void BindData()
        {
            Store store = this.GridPanel1.GetStore();
            
            store.DataSource = this.Data;
            store.DataBind(); 
        }
    
        private object[] Data
        {
            get
            {
                DateTime now = DateTime.Now;
    
                return new object[]
                {
                    new object[] { "3m Co", 71.72, 0.02, 0.03, now },
                    new object[] { "Alcoa Inc", 29.01, 0.42, 1.47, now },
                    new object[] { "Altria Group Inc", 83.81, 0.28, 0.34, now },
                    new object[] { "American Express Company", 52.55, 0.01, 0.02, now },
                    new object[] { "American International Group, Inc.", 64.13, 0.31, 0.49, now },
                    new object[] { "AT&T Inc.", 31.61, -0.48, -1.54, now }
                };
            }
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            
            <ext:Button runat="server" Text="Insert Record">
                <DirectEvents>
                    <Click OnEvent="InsertRecord"></Click>
                </DirectEvents>
            </ext:Button>
            <ext:GridPanel
                ID="GridPanel1"
                runat="server" 
                Title="Array Grid" 
                Width="700">
                <Store>
                    <ext:Store ID="Store1" runat="server" OnReadData="MyData_Refresh" PageSize="10">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="company" />
                                    <ext:ModelField Name="price" Type="Float" />
                                    <ext:ModelField Name="change" Type="Float" />
                                    <ext:ModelField Name="pctChange" Type="Float" />
                                    <ext:ModelField Name="lastChange" Type="Date" />
                                </Fields>
                            </ext:Model>
                        </Model>                  
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:RowNumbererColumn runat="server" Width="35" />
                        <ext:Column runat="server" Text="Company" DataIndex="company" Flex="1" />
                        <ext:Column runat="server" Text="Price" Width="75" DataIndex="price">
                        </ext:Column>
                        <ext:Column runat="server" Text="Change" Width="75" DataIndex="change">
                        </ext:Column>
                        <ext:Column runat="server" Text="Change" Width="75" DataIndex="pctChange">
                        </ext:Column>
                        <ext:DateColumn runat="server" Text="Last Updated" Width="85" DataIndex="lastChange" Format="H:mm:ss" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </form>
    </body>
    </html>
  3. #3
    looks great, but I need that initially the store is empty, do not need the following:

    private object[] Data
        {
            get
            {
                DateTime now = DateTime.Now;
     
                return new object[]
                {
                    new object[] { "3m Co", 71.72, 0.02, 0.03, now },
                    new object[] { "Alcoa Inc", 29.01, 0.42, 1.47, now },
                    new object[] { "Altria Group Inc", 83.81, 0.28, 0.34, now },
                    new object[] { "American Express Company", 52.55, 0.01, 0.02, now },
                    new object[] { "American International Group, Inc.", 64.13, 0.31, 0.49, now },
                    new object[] { "AT&T Inc.", 31.61, -0.48, -1.54, now }
                };
            }
        }
    I can now insert records without using databind, when I use the command databind, clean the gridpanel,
    I did so:

    StoreProcRecPasos.Add(New With { _
                     .Nombre = txtNombre.Text, _
                     .Peso = NumFieldPeso.Number, _
                     .Obligatorio = resp, _
                     .Duracion = txtDurac.Text, _
                     .Porcentaje = Porcentaje, _
                     .TipoCalificacion = cmbTipoCalificacion.SelectedItem.Value, _
                     .EnviaAlerta = alerta, _
                     .JefeInmediato = jefe, _
                     .Solicitante = solicitante, _
                     .UsuarioEspec = usuario _
                    })
    
                    StoreProcRecPasos.DataBind()
    how I can insert records even when the store is empty?

    thanks!
    Last edited by Daniil; Feb 07, 2013 at 4:40 AM. Reason: Please use [CODE] tags
  4. #4
    already solved,

    checking the thread: Help Forum HomeCommunity Forums1.x Add record to store, I found using the command:
    storeHorarios.CommitChanges();
    thanks!
    Last edited by Daniil; Feb 07, 2013 at 4:41 AM. Reason: Please use [CODE] tags

Similar Threads

  1. [CLOSED] Insert store records performance
    By softmachine2011 in forum 2.x Legacy Premium Help
    Replies: 11
    Last Post: Dec 14, 2012, 9:35 AM
  2. Replies: 0
    Last Post: Oct 22, 2012, 9:55 AM
  3. Replies: 2
    Last Post: Apr 11, 2012, 8:33 PM
  4. Replies: 3
    Last Post: Feb 18, 2011, 2:18 PM
  5. insert records in gridpanel
    By pankaj in forum 1.x Help
    Replies: 0
    Last Post: Apr 01, 2010, 5:53 AM

Posting Permissions