[CLOSED] How to load formpanel textfields with data from sql database

  1. #1

    [CLOSED] How to load formpanel textfields with data from sql database

    Hello Daniil, I would like ask you for help. I have formpanel with some textfield,datefield etc. and I need fill this formpanel with data from sql database by use of SqlDataReader object (or similar). I think that there is some method to databind & fill textfileds in FormPanel with record read from database. Thank you for help. ASAPCH

    <ext:FormPanel 
                    ID="formpanelBasic" 
                    runat="server" 
                    Title="Basic"
                    DefaultAnchor="100%"
                    BodyPadding="5">
                    <Items>
                        <ext:TextField ID="FirstName" runat="server" FieldLabel="First Name" Name="FirstName" />
                        <ext:TextField ID="LastName" runat="server" FieldLabel="Last Name" Name="LastName" />
                        <ext:DateField ID="EntryDate" runat="server" FieldLabel="Entry date" Format="yyyy-MM-dd" Name="EntryDate" />
                    </Items>
      </ext:FormPanel> 
    .....
    .....
                    SqlDataReader myDataReader = GetSQLRecordById(id);
                    if (myDataReader.Read())
                    {
                        formpanelBasic.SetValues(myDataReader);// this doesnt work
                       // following code I want to replace with one function call
                       this.FirstName.Text = myDataReader["FirstName"].ToString();
                        this.LastName.Text = myDataReader["LastName"].ToString();
                       this.EntryDate.Text = String.Format("{0:yyyy-MM-dd}", myDataReader["EntryDate"]); }
    ....
    Last edited by Daniil; Nov 15, 2012 at 2:38 PM. Reason: [CLOSED]
  2. #2
    Hi @ASAPCH,

    Please use a Store to bind a data from a database. Then load a Store's record to a FormPanel. Here is an example.
    https://examples2.ext.net/#/Form/Mis...ous/Form_View/
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @ASAPCH,

    Please use a Store to bind a data from a database. Then load a Store's record to a FormPanel. Here is an example.
    https://examples2.ext.net/#/Form/Mis...ous/Form_View/
    Hi Daniil, thanks for reply. Please do you know how to fill form from code behind? There are no methods getForm() & loadRecord () in ext:FormPanel object. Another question: is ext:TextField content bind with store/database column through atribute "Name" of TextField ?

    <ext:TextField ID="FirstNameID" runat="server" FieldLabel="First Name" Name="FirstName" />
    Thanks. ASAPCH
  4. #4
    Quote Originally Posted by ASAPCH View Post
    Please do you know how to fill form from code behind? There are no methods getForm() & loadRecord () in ext:FormPanel object.
    Please look at the example how you can use a SetValues method.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                var values = new
                {
                    TextField1 = "1",
                    TextField2 = "2"
                };
                
                this.FormPanel1.SetValues(values);    
            }
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:FormPanel ID="FormPanel1" runat="server">
                <Items>
                    <ext:TextField runat="server" Name="TextField1" />
                    <ext:TextField runat="server" Name="TextField2" />
                </Items>
            </ext:FormPanel>
        </form>
    </body>
    </html>

    Quote Originally Posted by ASAPCH View Post
    Another question: is ext:TextField content bind with store/database column through atribute "Name" of TextField ?

    <ext:TextField ID="FirstNameID" runat="server" FieldLabel="First Name" Name="FirstName" />
    Yes, ModelField's Name is associated with field's Name.
  5. #5
    Quote Originally Posted by Daniil View Post
    Please look at the example how you can use a SetValues method.

    Example
    [CODE]<%@ Page Language="C#" %>

    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

    <script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!X.IsAjaxRequest)
    {
    var values = new
    {
    TextField1 = "1",
    TextField2 = "2"
    };

    this.FormPanel1.SetValues(values);
    }
    }
    </script>

    Yes, ModelField's Name is associated with field's Name.
    Ok Daniil, my case is following: I have infinite remote buffered grid with Store filled from SQL database, after user doubleclick on row detail form window(in ASCX, ASCX.cs) should be opened. I have tried:

        public bool SetFormValues(int id)       // DB read & fill form
            {
    
                var record = this.GridStore.GetById(id);
                formpanelBasic.SetValues(record);
                return true;
            }
    .. but this ended with crash. Another question is: method GetById(id) returns ModelProxy, but how can I get proper record data(columns from DB) from this?
    Another choice is to do this not in code behind but in script:

    var onItemDblClick = function (record, index, e ) { 
                #{TestDetail1}.formpanelBasic.getForm().loadRecord(record)
                #{TestDetail1}.Show();
            }
     ...
            <Listeners>
                    <ItemDblClick Handler="onItemDblClick  ( record, index, e  );" />
                </Listeners>
            </ext:GridPanel>
    ... 
    <uc1:TestDetail ID="TestDetail1" runat="server" />
    ..but I have problem in reference to formpanelBasic ( is in detail window in separate ascx file )

    Thanks. ASAPCH
    Last edited by ASAPCH; Nov 09, 2012 at 5:08 PM.
  6. #6
    Quote Originally Posted by ASAPCH View Post
    Ok Daniil, my case is following: I have infinite remote buffered grid with Store filled from SQL database, after user doubleclick on row detail form window(in ASCX, ASCX.cs) should be opened. I have tried:

        public bool SetFormValues(int id)       // DB read & fill form
            {
    
                var record = this.GridStore.GetById(id);
                formpanelBasic.SetValues(record);
                return true;
            }
    .. but this ended with crash.
    Please use LoadRecord method.


    Quote Originally Posted by ASAPCH View Post
    Another question is: method GetById(id) returns ModelProxy, but how can I get proper record data(columns from DB) from this?
    It is not submitted from client automatically. You can submit it manually. Or, at least, a record's id to retrieve the rest data from a database.

    Quote Originally Posted by ASAPCH View Post
    Another choice is to do this not in code behind but in script:
    var onItemDblClick = function (record, index, e ) { 
                #{TestDetail1}.formpanelBasic.getForm().loadRecord(record)
                #{TestDetail1}.Show();
            }
     ...
            <Listeners>
                    <ItemDblClick Handler="onItemDblClick  ( record, index, e  );" />
                </Listeners>
            </ext:GridPanel>
    ... 
    <uc1:TestDetail ID="TestDetail1" runat="server" />
    ..but I have problem in reference to formpanelBasic ( is in detail window in separate ascx file )
    You can set IDMode="Static" for the FormPanel. Then its client reference will be:
    App.FormPanelServerID
    Obviously, it is not an option if you want to use multiple instance of a TestDetail control. In this case you should come up with another solution to manage client references.

    By the way I would suggest you to look into MessageBus feature.
    https://examples2.ext.net/#/search/messagebus

Similar Threads

  1. [CLOSED] How to load FormPanel data using DirectMethods
    By jchau in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Sep 18, 2012, 10:53 AM
  2. Cant Load data from Grid Panel into Formpanel
    By nukarsoft in forum 2.x Help
    Replies: 0
    Last Post: Sep 04, 2012, 8:59 PM
  3. Replies: 12
    Last Post: Feb 20, 2012, 1:58 PM
  4. FormPanel that moves the load data
    By threewonders in forum 1.x Help
    Replies: 0
    Last Post: Feb 25, 2011, 8:48 AM
  5. [CLOSED] Load data from the database in the grid.
    By flaviodamaia in forum 1.x Help
    Replies: 2
    Last Post: Oct 23, 2008, 9:00 AM

Tags for this Thread

Posting Permissions