gridpanel databinding

  1. #1

    gridpanel databinding

    just downloaded the contols of ext.net & trying some samples
    i want to bind grid with data as shown in
    https://examples2.ext.net/#/GridPane...tails/Binding/

    but i want 2 bind it in code behind

    i hve <ext:GridPanel ID="GridPanel1" runat="server" Height="300" Title="Title">
    </ext:GridPanel> in aspx page
    is it same like binding normal gridview of asp.net?
  2. #2
  3. #3
    there is no code behind for this
    something which i tried
    STR = "select * from Contact";
    SqlDataAdapter da = new SqlDataAdapterSTR, conn);
    DataTable dt = new DataTable();

    da.Fill(dt);

    Store1.DataSource = dt;
    Store1.DataBind();
    GridPanel1.DataBind();

    but dont get anything on the page , neither thae data nor the grid
    Last edited by svk; May 04, 2012 at 12:54 PM.
  4. #4
    I am not sure it works with a DataTable try creating an IList or an array and then use it as the datasource.
    don't forget to tell the store which properties to use. again, look at the example that i posted, try to run it
    and afterwards modify it to suit your needs.

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.GridPanel1.Store.Primary.DataSource = new List<object>
                {
                    new { 
                        Id = "0001",
                        Value = 1, 
                        Text = "One"
                    },
                    new { 
                        Id = "0002",
                        Value = 2, 
                        Text = "Two"
                    },
                    new { 
                        Id = "0003",
                        Value = 3, 
                        Text = "Three"
                    },
                    new { 
                        Id = "0004",
                        Value = 4, 
                        Text = "Four"
                    },
                    new { 
                        Id = "0005",
                        Value = 5, 
                        Text = "Five"
                    }
                };
    
                this.GridPanel1.Store.Primary.DataBind();
            }
        }
  5. #5
    private static void ContactList()
    {

    System.Collections.Generic.List<contact> contactList = new System.Collections.Generic.List<contact>();

    i have made this ilist collection

    and aslo
    <ext:GridPanel ID="GridPanel1" runat="server" Height="300" Title="Title">
    <Store>
    <ext:Store ID="Store1" runat="server" GroupField="ContactID" >
    with columns defined

    how do i bind the list to the gridpanel or store so that i get the data from codebehind
  6. #6
    Lets say that these contacts of yours have FirstName and LastName property.
    Put a reader in the store that will be able to interpret the list data that you are binding.
    Tell the reader to look at the FirstName and LastName properties of the objects that
    you are providing it with.

    Then tell the Grid to use the FirstName and LastName properties that reader read as data in the columns.

    Pay special attention to the Reader element inside the srore and to the DataIndex attribute of the Column elements.


    
            <ext:ResourceManager runat="server" />
            
            <h1>Contacts GridPanel</h1>
            
            <ext:GridPanel 
                ID="GridPanel1" 
                runat="server"
                Width="300"
                Height="200"
                Title="ContactsGrid">
                <Store>
                    <ext:Store runat="server">
                        <Reader>
                            <ext:JsonReader>
                                <Fields>
                                    <ext:RecordField Name="FirstName" Type="String" />
                                    <ext:RecordField Name="LastName" Type="String" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel>
                    <Columns>
                        <ext:RowNumbererColumn />
                        <ext:Column 
                            Header="First Name" 
                            DataIndex="FirstName" 
                            Width="130" 
                            Sortable="true">
                            <Editor>
                                <ext:TextField runat="server" AllowBlank="false" />
                            </Editor>
                        </ext:Column>
                        <ext:Column 
                            Header="Last Name" 
                            DataIndex="LastName" 
                            Width="130" 
                            Sortable="true">
                            <Editor>
                                <ext:TextField runat="server" AllowBlank="false" />
                            </Editor>
                        </ext:Column>
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
  7. #7
    done as per the reply

    but still not able to get the grid binded to db

    i tried to bind as per link
    http://www.c-sharpcorner.com/Blogs/7...f-ext-net.aspx but getting error at using

    html design

    <ext:GridPanel ID="GridPanel1" runat="server" Width="600" Height="400" Title="ContactsGrid">
    <Store>
    <ext:Store ID="Store1" runat="server">
    <Reader>
    <ext:JsonReader>
    <Fields>
    <ext:RecordField Name="FName" Type="String" />
    <ext:RecordField Name="LName" Type="String" />
    <ext:RecordField Name="Ecode" Type="String" />
    </Fields>
    </ext:JsonReader>
    </Reader>
    </ext:Store>
    </Store>
    <ColumnModel>
    <Columns>
    <ext:RowNumbererColumn />
    <ext:Column Header="Name" DataIndex="FName" Width="130" Sortable="true">
    <Editor>
    <ext:TextField ID="TextField1" runat="server" AllowBlank="false" />
    </Editor>
    </ext:Column>
    <ext:Column Header="MiddleName" DataIndex="LName" Width="130" Sortable="true">
    <Editor>
    <ext:TextField ID="TextField2" runat="server" AllowBlank="false" />
    </Editor>
    </ext:Column>
    <ext:Column Header="EmailAddress" DataIndex="ECode" Width="130" Sortable="true">
    <Editor>
    <ext:TextField ID="TextField3" runat="server" AllowBlank="false" />
    </Editor>
    </ext:Column>
    </Columns>
    </ColumnModel>
    </ext:GridPanel>


    i hve a class file contact


    public class contact
    {

    private string _FirstName = string.Empty;
    private string _MiddleName = string.Empty;
    private string _email = string.Empty;

    public contact()
    {

    }

    public contact(string fn, string mn,string email)
    {
    this._FirstName = fn;
    this._MiddleName = mn;
    this._email = email;
    }





    public string FirstName
    {
    get
    {
    return _FirstName;
    }
    set
    {
    _FirstName = value;
    }
    }

    public string MiddleName
    {
    get
    {
    return _MiddleName;
    }
    set
    {
    _MiddleName = value;
    }
    }
    public string Email
    {
    get
    {
    return _email;
    }
    set
    {
    _email = value;
    }
    }


    //--------------- code in .cs page
    if (!X.IsAjaxRequest)
    {

    //this.BindData();
    System.Collections.Generic.List<contact> contactList = new System.Collections.Generic.List<contact>();
    //string connStr = ConfigurationSettings.AppSettings["ConnString"];
    //SqlConnection conn = new SqlConnection(connStr);
    SqlCommand myCommand = new SqlCommand("select * from EMP_PERSONAL ", conn);
    conn.Open();
    SqlDataReader reader = myCommand.ExecuteReader();
    while (reader.Read())
    {
    contact Contact = new contact();
    Contact.FirstName = reader["FName"].ToString();
    Contact.MiddleName = reader["LName"].ToString();
    Contact.Email = reader["Ecode"].ToString();
    contactList.Add(Contact);
    }

    conn.Close();
    myCommand.Dispose();
    Store1.DataSource = contactList;
    Store1.DataBind();
    GridPanel1.DataBind();

    }


    though there is no error data is not displayed in the grid , i do get the data in
    Contact.FirstName = reader["FName"].ToString();
    Contact.MiddleName = reader["LName"].ToString();
    Contact.Email = reader["Ecode"].ToString();
    Last edited by svk; May 07, 2012 at 1:52 AM.

Similar Threads

  1. [CLOSED] MVC GridPanel Databinding
    By adelaney in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: May 14, 2012, 9:17 PM
  2. Replies: 0
    Last Post: Jun 21, 2011, 2:51 AM
  3. help with databinding (ext:GridPanel)
    By vikram1983 in forum 1.x Help
    Replies: 2
    Last Post: Apr 05, 2011, 1:07 PM
  4. DataBinding GridPanel/Store/Reader
    By nuno_Santos in forum 1.x Help
    Replies: 4
    Last Post: Apr 01, 2009, 2:18 PM
  5. GridPanel DataBinding
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 13, 2008, 10:24 PM

Posting Permissions