[CLOSED] Creating Store and GridPanel Dynamically

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Creating Store and GridPanel Dynamically

    Hi there

    I am trying to make store and GridPanel Dynamically on Page_Load which is working fine Below is my Code
    in the below code i call a "bindstore()" function which builds the store and inside "bindstore()" i call a function "BuildGridPanel()" which builds
    columnModel and columns in the gridpanel.


    .ASPX
    *<ext:Store ID="strReportViewer" runat="server">
    * * * * * * * * </ext:Store>
    * * * * * * * * <ext:Container ID="Container1" runat="server" Region="East">
    * * * * * * * * * * <Items>
    * * * * * * * * * * * * <ext:Panel ID="Panel1" runat="server" Region="West" Title="Reports" Width="1001">
    * * * * * * * * * * * * * * <Items>
    * * * * * * * * * * * * * * * * <ext:GridPanel ID="gpReportViewer" EnableViewState="true" Width="1000" runat="server">
    * * * * * * * * * * * * * * * * </ext:GridPanel>
    * * * * * * * * * * * * * * </Items>
    * * * * * * * * * * * * </ext:Panel>
    * * * * * * * * * * </Items>
    * * * * * * * * </ext:Container>
    .ASPX.CS

    
     protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    bindStore();
                  
                }
               
            }
    
    private void bindStore()
            {
                DataSet dsRecordFindRecord = new DataSet();
                DataSet finaldataset = new DataSet();
                if (Repid == "" || Repid == null)
                {
                    finaldataset = fn.Selectdata(fn.Selectsinglevalues("select repReportSQL from tc_ReportCatalogue where pk_ReportId = '8'"));
                    
                }
                else
                {
                    finaldataset = fn.Selectdata(fn.Selectsinglevalues("select repReportSQL from tc_ReportCatalogue where pk_ReportId = '" + Repid + "'"));
                
                }
           //     Ext.Net.Store Store1 = new Ext.Net.Store();
                strReportViewer.DataSource = finaldataset;
                //Store1.GroupField = "empLocation";
                Ext.Net.Model storereader = new Ext.Net.Model();
                //storereader.IDProperty = "empNo";
    
                for (int c = 0; c < finaldataset.Tables[0].Columns.Count; c++)
                {
                    Ext.Net.ModelField rf = new Ext.Net.ModelField();
                    rf.Name = finaldataset.Tables[0].Columns[c].ColumnName;
                    storereader.Fields.Add(rf);
                }
    
    
                strReportViewer.Model.Add(storereader);
                strReportViewer.DataBind();
                BuildGridPanel(finaldataset);
                gpReportViewer.Store.Add(strReportViewer);
                gpReportViewer.DataBind();
            }
    
    
    
       public void BuildGridPanel(DataSet ds)
            {
    
                gpReportViewer.Width = Unit.Pixel(1000);
                gpReportViewer.Height = Unit.Pixel(500);
                DataSet dsgetcol = ds;
                //////XXXXXXXXXXXXXX/////////// 
                ////For Fetching columns display name///
                string columns = "";
                for (int chk = 0; chk < dsgetcol.Tables[0].Columns.Count; chk++)
                {
    
                    columns = columns + dsgetcol.Tables[0].Columns[chk].ColumnName + ",";
                    //gpReportViewer.ColumnModel.Columns.RemoveAt(chk);
                }
                columns.Remove(columns.Length - 1);
                string[] colname = columns.Split(',');
                ////for adding column model to gridpanel
                
                for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
                {
                    Ext.Net.Column col = new Ext.Net.Column();
                    col.ID = ds.Tables[0].Columns[i].ColumnName;
                    col.Text = colname[i];
                    col.DataIndex = ds.Tables[0].Columns[i].ColumnName;
                    col.Align = Ext.Net.Alignment.Left;
                    col.Sortable = true;
                    //col.Groupable = true;
                   //col.Lockable = true;
    
                    //col.SummaryType = Ext.Net.SummaryType.Average;
                    gpReportViewer.ColumnModel.Columns.Add(col);
                }
            }

    It All Works Fine at the first time but when am trying to rebind every thing on click of a treePanel Node
    its not working below is the code of TreeNode Click

    .aspx (DirectEvet Tag Inside TreePanel)

    
    
     <DirectEvents>
                                            <ItemClick OnEvent="Refresh_Grid" Before="if(!record.data.leaf){return false;};">
                                                <ExtraParams>
                                                    <ext:Parameter Name="id" Value="record.data.id" Mode="Raw" />
                                                </ExtraParams>
                                            </ItemClick>
                                        </DirectEvents>
    .aspx.cs

      protected void Refresh_Grid(object sender, DirectEventArgs e)
            {
                string Id = e.ExtraParams["id"].ToString();
                Repid = e.ExtraParams["id"].ToString();
                bindStore();
             
    
            }

    Please help


    Thanks in advance
    Last edited by Daniil; Apr 02, 2013 at 9:27 AM. Reason: [CLOSED]
  2. #2
    Hi Tonic,

    Do you need to bind new data only? Or do you also need to reconfigure the GridPanel (e.g. remove/add columns)?
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi Tonic,

    Do you need to bind new data only? Or do you also need to reconfigure the GridPanel (e.g. remove/add columns)?
    Only new Data No Remove or add
  4. #4
    Do you need to change a Store's Model?
  5. #5
    Quote Originally Posted by Daniil View Post
    Do you need to change a Store's Model?
    yes i need to change model on each request
  6. #6
    Well, it means that you need to change Columns, doesn't? Just you said that you don't need to add/remove Columns. It is confusing.
  7. #7
    Quote Originally Posted by Daniil View Post
    Well, it means that you need to change Columns, doesn't? Just you said that you don't need to add/remove Columns. It is confusing.

    Oh sorry I thought you are asking for giving facility to user at the run time to add new record or delete record with a click of a button or something

    let me clarify this

    on each request i rebind the store (change the Model) , and then regenerate the Columns as per the model.
  8. #8
    Ok, thank you for clarifying.

    According to your requirement it would be simplest to re-render the GridPanel.

    Your Refresh_Grid DirectEvent handler should work if you do the following changes.

    1. Add this to the end of the BuildGridPanel method.
    if (X.IsAjaxRequest)
    {
        gpReportViewer.Render();
    }
    2. Set up some ID explicitly for a GridPanel (the same for each request). The Render method will use it to remove a previously rendered GridPanel.
  9. #9
    Quote Originally Posted by Daniil View Post
    Ok, thank you for clarifying.

    According to your requirement it would be simplest to re-render the GridPanel.

    Your Refresh_Grid DirectEvent handler should work if you do the following changes.

    1. Add this to the end of the BuildGridPanel method.
    if (X.IsAjaxRequest)
    {
        gpReportViewer.Render();
    }
    2. Set up some ID explicitly for a GridPanel (the same for each request). The Render method will use it to remove a previously rendered GridPanel.

    Can you please clarify your second point further
  10. #10
    The Render method generates a piece of JavaScript to render a GridPanel. Before creating a GridPanel it destroys a component with a GridPanel's ID to avoid ids conflict.
Page 1 of 2 12 LastLast

Similar Threads

  1. creating shortcut dynamically
    By softlabsgroup.support in forum 1.x Help
    Replies: 0
    Last Post: Jun 06, 2012, 12:27 PM
  2. Replies: 0
    Last Post: Mar 27, 2012, 10:01 AM
  3. Replies: 2
    Last Post: Nov 23, 2011, 1:02 AM
  4. Issue when creating Menuitems dynamically
    By kondareddy1984 in forum 1.x Help
    Replies: 1
    Last Post: Mar 11, 2011, 5:47 PM
  5. Replies: 2
    Last Post: Mar 02, 2010, 1:50 AM

Posting Permissions