[CLOSED] Dynamic Labels Grid/Reader/Store

  1. #1

    [CLOSED] Dynamic Labels Grid/Reader/Store

    Hello,

    is it somehow possible to implement a Grid which uses a DataTable/ SqlDataSource.Command/.. whatever and which
    generates the Columns and Colum-Namings by itself?

    For example:

    SELECT column1 AS NAME, colum2 AS STREET, column3 AS PHONE FROM table;
    This should create a grid with Name, STreet and Phone:

    Name     |       Street       | Phone       |
    ---------------------------------------------
    I am sure it can be implemented in codebehind by parsing the SQL-Select to get out Name, Street, Phone and so on via Search/Split/...-Operations. Should I do it like that or are there easier ways?

    Regards,

    Martin
    Last edited by geoffrey.mcgill; Dec 13, 2010 at 6:41 PM. Reason: please use [CODE] tags, [CLOSED]
  2. #2
    Hi,

    No, Store/Grid don't support autogenerating. You have to manually add fields and columns (for example, read DataTable columns and add the same fields and grid's columns)

    If you have any complications with it then I can prepare a sample for you
  3. #3
    Hi,

    I'm hoping to implement an "AutoGenerate" feature in a future release (v1.x?) release.
    Geoffrey McGill
    Founder
  4. #4
    Hi,

    Can you post a sample, I would like to see how to achieve the AutoGenerate Grid...

    thanks
  5. #5
    Quote Originally Posted by cobiscorp View Post
    Hi,

    Can you post a sample, I would like to see how to achieve the AutoGenerate Grid...

    thanks
    This functionality is not currently included with the GridPanel.
    Geoffrey McGill
    Founder
  6. #6
    Hi,

    Here is the sample demonstrates how to build the grid depends from DataTable data
    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Import Namespace="System.Data" %>
    
    <script runat="server">
        
        private RecordFieldType MappingType(Type type)
        {
            if (type == typeof(string))
            {
                return RecordFieldType.String;
            }
            else if (type == typeof(DateTime))
            {
                return RecordFieldType.Date;
            }
            else if (type == typeof(int))
            {
                return RecordFieldType.Int;
            }
            else if (type == typeof(double))
            {
                return RecordFieldType.Float;
            }
            else if (type == typeof(bool))
            {
                return RecordFieldType.Boolean;
            }
    
            return RecordFieldType.Auto;
        }    
        
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("StringColumn", typeof(string));
            dt.Columns.Add("DateTimeColumn", typeof(DateTime));
            dt.Columns.Add("IntColumn", typeof(int));
            dt.Columns.Add("DoubleColumn", typeof(double));
            dt.Columns.Add("BoolColumn", typeof(bool));
    
            DateTime now = DateTime.Now;
            
            for (int i = 1; i <= 10; i++)
            {
                dt.Rows.Add("s" + i, now.AddDays(i), i, i*1.0, (i & 1) == 0);
            }
    
            JsonReader reader = new JsonReader();
            
            Store store = new Store
            {
                ID = "Store1",
                Reader = { 
                    reader
                }
            };
    
            GridPanel grid = new GridPanel
            {
                ID = "GridPanel1",
                AutoHeight = true,
                Store = {
                    store
                }
            };
    
            this.Form.Controls.Add(grid);
    
            foreach (DataColumn column in dt.Columns)
            {
                reader.Fields.Add(column.ColumnName, this.MappingType(column.DataType));
                grid.ColumnModel.Columns.Add(new Column { Header = column.ColumnName, DataIndex = column.ColumnName, Width=200 });
            }
    
            store.DataSource = dt;
            store.DataBind();
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            
        </form>
    </body>
    </html>
  7. #7
    Hi Daniil,

    Thanks for the help. However, when I have DataTable object with data in my application and I want to assign it to the datasource property of Store then why it does not work. I have store with JsonReader and 2 dummy columns in my store. At runtime, I get the dataTable from database and adds 2 blank columns in dataTable and then I assign it to my store so that column mapping match exactly. Furthermore, I have debugged the code and made sure that 2 blank datacolums are added to the datatable. But after binding data of gridpanel and store nothing gets rendered on page. I know that we can remove all fields of store and the recreate it at runtime, so I want to know If there is anyway around.

    Do I need to change the presentation of data in DataTable to any other object ? and If so then how can I do it. Can you please give me little sample code so that I can understand the inner working of these 2 objects.

    Thanks.

Similar Threads

  1. Replies: 12
    Last Post: Sep 20, 2011, 2:33 PM
  2. Replies: 0
    Last Post: Mar 04, 2011, 6:46 AM
  3. [CLOSED] Reader id issue in Store
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 20, 2011, 12:04 PM
  4. Replies: 1
    Last Post: Feb 24, 2010, 3:05 PM
  5. [CLOSED] dynamic labels
    By alexp in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 10, 2009, 2:53 PM

Tags for this Thread

Posting Permissions