Gridpanel with unknown columns

  1. #1

    Gridpanel with unknown columns

    Hi All,
    I am trying to use Gridpanel.I succeed with the example given on the sit.
    But in each example no. of columns in Grid is known.
    There is a property in Gridview,AutoGenerateColumn = true,so I don't need to specify column names.
    (As in my case the columns will be auto generated as per the selection criteria.)

    Can I bind a dynamic datatable to Gridpanel/Store?
    I tried but it's not working for me.
    Please help.
  2. #2

    Help here

    I am trying hard with this.Now I have written code like this on button click.But having some problem.Please see.

    JsonReader jsonread = new JsonReader();
    ColumnBase[] cb = new ColumnBase[dtReturn.Columns.Count];
    int i=0;
    foreach (DataColumn dc in dtReturn.Columns)
    {
    jsonread.Fields.Add(dc.ColumnName.ToString());
    cb[i].ColumnID.Insert(i,dc.ColumnName.ToString());
    i++;
    }
    Store1.Reader.Add(jsonread);


    GridPanel1.ColumnModel.Columns.Add(cb); // Getting error here.

    this.Store1.DataSource = dtReturn;
    this.Store1.DataBind();
  3. #3
    Quote Originally Posted by rajputamit View Post
    I am trying hard with this.Now I have written code like this on button click.But having some problem.Please see.

    JsonReader jsonread = new JsonReader();
    ColumnBase[] cb = new ColumnBase[dtReturn.Columns.Count];
    int i=0;
    foreach (DataColumn dc in dtReturn.Columns)
    {
    jsonread.Fields.Add(dc.ColumnName.ToString());
    cb[i].ColumnID.Insert(i,dc.ColumnName.ToString());
    i++;
    }
    Store1.Reader.Add(jsonread);


    GridPanel1.ColumnModel.Columns.Add(cb); // Getting error here.

    this.Store1.DataSource = dtReturn;
    this.Store1.DataBind();
    You have some mistakes. Please change your code same as below code:

    
            JsonReader jsonread = new JsonReader();
            ColumnBase[] cb = new ColumnBase[dt.Columns.Count];
            int i = 0;
            foreach (DataColumn dc in dt.Columns)
            {
                jsonread.Fields.Add(dc.ColumnName.ToString());
                cb[i] = new Ext.Net.Column();
                cb[i].ColumnID = dc.ColumnName.ToString();
                i++;
            }
    
            Store1.Reader.Add(jsonread);
            GV_Preview.ColumnModel.Columns.AddRange(cb); 
            Store1.DataSource = dt;
            Store1.DataBind();
            Store1.Render(GV_Preview);
            GV_Preview.Render(pnlPreview);
  4. #4

    Othe method for add column to Gridpanel dynamically

    In addition, I suppose this method is better:

    
            foreach (DataColumn dc in dt.Columns)
            {
                Store1.Reader[0].Fields.Add(dc.ColumnName);
                Ext.Net.ColumnBase col = new Ext.Net.Column();
                col.DataIndex = dc.ColumnName;
                col.Width = new Unit("85px");
                col.Wrap = false;
                col.Sortable = false;
                col.Align = Ext.Net.Alignment.Center;
                GridPanel1.AddColumn(col);
            }

Similar Threads

  1. [CLOSED] GridPanel with many columns
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 04, 2011, 9:39 PM
  2. How to add a tip for Gridpanel's Columns ?
    By Yanfang Wang in forum 1.x Help
    Replies: 8
    Last Post: Jun 07, 2010, 11:14 AM
  3. Can we merge columns in gridpanel
    By Satyanarayana murthy in forum 1.x Help
    Replies: 2
    Last Post: Feb 26, 2010, 9:51 AM
  4. gridpanel columns and rows
    By gpcontreras in forum 1.x Help
    Replies: 1
    Last Post: Feb 02, 2010, 10:26 PM
  5. Unknown server tag 'asp:RecordField'.
    By lindgrenm in forum 1.x Help
    Replies: 2
    Last Post: Sep 17, 2009, 9:32 AM

Tags for this Thread

Posting Permissions