Bind GridPanel to a DataTable in code behind by autogenerating columns in the Store

  1. #1

    Bind GridPanel to a DataTable in code behind by autogenerating columns in the Store

    Can anybody post some sample code clearly demonstrating how to bind a GridPanel to a DataTable in code behind by autogenerating columns?

    In my case, I have a GridPanel in the South region of a BorderLayout (which is within a ViewPort) and and I am trying to bind a datatable to a GridPanel in a server side event. However, it doesn't work. The GridPanel just shows up with a paging toolbar at the bottom but with no records.

    I used some sample code from another post in this forum which helped me display the records in the GridPanel. However, this sample code required me to place the GridPanel and its Store in a separate ASPX page which I tried to embed as an IFrame in a popup Window and I ended up having trouble with AutoLoad of the Window control (please see my other posts).

    I want to accomplish the following two tasks:

    1. Dynamically display datatable rows in the GridPanel in the South region of the BorderLayout in a ViewPort.

    2. Pop up a Window control with a GridPanel embedded in it (Merge or IFrame) displaying the rows from a datatable.

    Anybody, please help!

    Thanks a lot!
  2. #2

    RE: Bind GridPanel to a DataTable in code behind by autogenerating columns in the Store

    GridFilters filters = new GridFilters();
    filters.Local = true;
    GridPanelMovimenti.Plugins.Add(filters);

    int _n = 0;
    int kkk = 0;
    foreach (DataColumn dc in tmptable.Columns)
    {

    // ADD Column to the Reader
    if (_n == 0) // If primary key column
    ((Coolite.Ext.Web.JsonReader)this.StoreMovimenti.R eader[0]).ReaderID = "Shashi";

    if (kkk == 0)
    {
    ((Coolite.Ext.Web.JsonReader)this.StoreMovimenti.R eader[0]).Fields.Add(new Coolite.Ext.Web.RecordField(dc.Caption, Coolite.Ext.Web.RecordFieldType.String));
    StringFilter sf = new StringFilter();
    sf.DataIndex = dc.Caption;
    filters.Filters.Add(sf);

    }
    else if (kkk == 1)
    {
    ((Coolite.Ext.Web.JsonReader)this.StoreMovimenti.R eader[0]).Fields.Add(new Coolite.Ext.Web.RecordField(dc.Caption, Coolite.Ext.Web.RecordFieldType.String));
    StringFilter sf = new StringFilter();
    sf.DataIndex = dc.Caption;
    filters.Filters.Add(sf);

    }
    else
    {

    ((Coolite.Ext.Web.JsonReader)this.StoreMovimenti.R eader[0]).Fields.Add(new Coolite.Ext.Web.RecordField(dc.Caption, Coolite.Ext.Web.RecordFieldType.Float));
    NumericFilter nf = new NumericFilter();
    nf.DataIndex = dc.Caption;
    filters.Filters.Add(nf);

    }
    kkk = kkk + 1;
    //// ADD Column to columns collection


    if (kkk % 2 != 0)
    {
    Coolite.Ext.Web.Column _col = new Coolite.Ext.Web.Column();
    _col.ColumnID = dc.Caption;
    _col.Tooltip = dc.Caption;
    _col.Header = dc.Caption;
    _col.DataIndex = dc.Caption;
    _col.Resizable = true;
    _col.Sortable = true;
    _col.Width = 150;

    Renderer _objRen = new Renderer();
    _objRen.Fn = "ColRenderer";
    _col.Renderer = _objRen;
    GridPanelMovimenti.ColumnModel.Columns.Add(_col);
    }



    _n++;
    }
    pnlMov.Width = 150 * (_n / 2 + 1);
    this.StoreMovimenti.DataSource = tmptable;
    this.StoreMovimenti.DataBind();

Similar Threads

  1. Replies: 2
    Last Post: Apr 12, 2012, 5:44 AM
  2. Replies: 0
    Last Post: Jul 07, 2011, 8:19 PM
  3. Replies: 0
    Last Post: Mar 04, 2011, 12:05 PM
  4. Datatable and Store columns mapping
    By QualityCode in forum 1.x Help
    Replies: 0
    Last Post: Dec 16, 2010, 8:45 PM
  5. Bind Grito do Datatable
    By PoloTheMonk in forum 1.x Help
    Replies: 0
    Last Post: Nov 20, 2009, 1:20 PM

Posting Permissions