DateFormat problem in grid generated from codebehind

  1. #1

    DateFormat problem in grid generated from codebehind

    Hi,

    I'm trying to generate grid from codebehind. And I have promblem with date format in date-typed columns.

    Default4.apx is empty aspx page. There is just ext ScriptManager.

    Here is my code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using Cool = Coolite.Ext.Web;
    using System.Data;
    public partial class Default4 : System.Web.UI.Page
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            Control c = CreateUIGridsContainer(this);
            CreateUIGridMain(c, (new DataSet1TableAdapters.ReportConfigurationsTableAdapter()).GetData(), null);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected Control CreateUIGridsContainer(Page page)
        {
            UpdatePanel up = new UpdatePanel();
            up.ID = "up_grid";
            page.Form.Controls.Add(up);
            return up.ContentTemplateContainer;
        }
    
        protected void CreateUIGridMain(Control container, DataTable dt,  System.Collections.Generic.Dictionary<object, object> commandParameters)
        {
            string columnGroupName = dt.TableName;
            Cool.GridPanel grid = new Cool.GridPanel();
    
            Cool.Store store = new Cool.Store();
    
            foreach (DataColumn column in dt.Columns)
            {
                CreateUIGridColumn(grid, column.ColumnName, dt, store);
            }
            
            grid.Height = new Unit(300);
    
            // editable and buttons
            Cool.Button b = new Coolite.Ext.Web.Button();
            b.Icon = Coolite.Ext.Web.Icon.Disk;
            b.Text = "Save";
            grid.Buttons.Add(b);
            grid.Frame = true;
            grid.Title = "Test Grid";
            grid.StripeRows = true;
            grid.TrackMouseOver = true;
    
            container.Controls.Add(store);
    
            container.Controls.Add(grid);
            grid.StoreID = store.ID;
            BindUIGrid(store, dt);
        }
        protected void BindUIGrid(Control control, DataTable dt)
        {
            Cool.Store s = (Cool.Store)control;
    
            s.DataSource = dt;
            s.DataBind();
    
        }
        protected void CreateUIGridColumn(Control control, string columnName, DataTable item, Control store)
        {
            Cool.GridPanel gridView = (Cool.GridPanel)control;
    
            Cool.Store s = (Cool.Store)store;
    
            Cool.Column gridColumn = new Cool.Column();
            if (item != null)
            {
                switch (item.Columns[columnName].DataType.Name)
                {
                    case "DateTime":
                        Cool.DateField dateField = new Cool.DateField();
                        //when I put Vtype="date" I recieve JS error once I click on datepicker
                        dateField.Vtype = "daterange";
                        dateField.Format = "dd/MM/yyyy";
                        gridColumn.Editor.Add(dateField);
                        break;
                    default:
                        Cool.TextField field = new Cool.TextField();
                        gridColumn.Editor.Add(field);
                        break;
                }
            }
            gridColumn.DataIndex = columnName;
            gridColumn.Header = columnName;
            gridColumn.Sortable = false;
    
            gridView.ColumnModel.Columns.Add(gridColumn);
    
            if (s.Reader.Count == 0)
            {
                Cool.JsonReader reader = new Cool.JsonReader();
                s.Reader.Add(reader);
            }
            if (item != null)
            {
                switch (item.Columns[columnName].DataType.Name)
                {
                    case "DateTime":
                        //If I put here RecordFieldType.Date values in date column are not populated
                        //I tried different date formats "d", "d-m-Y"... - nothing happens
                        Cool.RecordField dateRecordField = new Coolite.Ext.Web.RecordField(columnName, Coolite.Ext.Web.RecordFieldType.Auto, "dd/MM/yyyy");
                        s.Reader[0].Fields.Add(dateRecordField);
                        break;
                    default:
                        Cool.RecordField rf = new Cool.RecordField(columnName, Cool.RecordFieldType.Auto);
                        s.Reader[0].Fields.Add(rf);
                        break;
                }
            }
        }
    }

  2. #2

    RE: DateFormat problem in grid generated from codebehind

    Anyone?



  3. #3

    RE: DateFormat problem in grid generated from codebehind

    Come on people, I'm still stuck with this.


Similar Threads

  1. [CLOSED] Version 1.2 Grid/Store DateFormat
    By ndotis in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Oct 04, 2011, 5:14 PM
  2. How to remove dynamically generated grid in code behind
    By mkshields9w57 in forum 1.x Help
    Replies: 0
    Last Post: Jul 07, 2011, 12:53 PM
  3. [CLOSED] Strange problem with dynamic generated Icons
    By macap in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Apr 16, 2010, 6:07 AM
  4. DateFormat in Grid Problem
    By bruce in forum 1.x Help
    Replies: 1
    Last Post: Mar 19, 2009, 8:47 AM
  5. Replies: 0
    Last Post: Feb 25, 2009, 6:05 PM

Posting Permissions