GridPanel not showing when method called in button directclick but show when method called in page_load event

  1. #1

    GridPanel not showing when method called in button directclick but show when method called in page_load event

    hello, I have this weird issue.
    I have a method which I call from button directclick event and also page_load event.
    when I call it from button directclick event, the data were not shown in a GridPanel.
    But when I call it from page_load event, the data were shown perfectly in a GridPanel.

    here is the sample code

    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager runat="server" ID="rms1" />
            <ext:GridPanel
                ID="GridPanel1"
                runat="server"
                Title="Resources"
                Width="800">
                <Store>
                    <ext:Store ID="Store1" runat="server" PageSize="10" />
                </Store>
    
                <SelectionModel>
                    <ext:RowSelectionModel runat="server" Mode="Multi" />
                </SelectionModel>
                <View>
                    <ext:GridView runat="server" StripeRows="true" />
                </View>
                <BottomBar>
                    <ext:PagingToolbar runat="server">
                        <Plugins>
                            <ext:ProgressBarPager runat="server" />
                        </Plugins>
                    </ext:PagingToolbar>
                </BottomBar>
    
            </ext:GridPanel>
    
            <ext:Button ID="btn1" runat="server" OnDirectClick="btn1_DirectClick" Text="load xls data" />
        </form>
    </body>
    </html>
    
    =====Behind Code=====
    
    protected void Page_Load(object sender, EventArgs e)
            {
                //if (!IsPostBack)
                //{
                //    this.BindDataFromXLS();
                //}
                //if (!X.IsAjaxRequest)
                //{
                //    this.BindDataFromXLS();
                //}
            }
            private void BindDataFromXLS()
            {
                XSSFWorkbook hssfwb;
                using (FileStream file = new FileStream(@"D:\lokih\sample2.xlsx", FileMode.Open, FileAccess.Read))
                {
                    hssfwb = new XSSFWorkbook(file);
                }
               
                ISheet sheet = hssfwb.GetSheetAt(1);
    
                DataTable dataTest = new DataTable(sheet.SheetName);
                IRow headerRow = sheet.GetRow(0);
                Model m = new Model();
                Store1.Model.Add(m);
                foreach (ICell headerCell in headerRow)
                {
                    dataTest.Columns.Add(Convert.ToString(headerCell));
                    m.Fields.Add(Convert.ToString(headerCell));
                    GridPanel1.ColumnModel.Columns.Add(new Column { DataIndex = Convert.ToString(headerCell), Text = Convert.ToString(headerCell) });
                }
                int rowIndex = 0, rowPosition = 0;
                foreach (IRow rowItem in sheet)
                {
                    if (rowIndex++ == 0) continue;
                    DataRow dataRow = dataTest.NewRow();
                    dataRow.ItemArray = rowItem.Cells.Select(c => Convert.ToString(c)).ToArray();
                    dataTest.Rows.Add(dataRow);
                    rowPosition++;
                }
    
                Store1 = this.GridPanel1.GetStore();
                Store1.DataSource = dataTest;
                Store1.DataBind();
                
            }
            
            protected void btn1_DirectClick(object sender, DirectEventArgs e)
            {
                this.BindDataFromXLS();
            }
    Hope there are some good explanations for these :D

    Thank you


    Attachment 24925
    Attachment 24930
    Attachment 24931
    Attachment 24932
    Attachment 24933
    Last edited by lokihnahta; May 03, 2017 at 4:07 AM.

Similar Threads

  1. Codebehind event called from Task
    By Alex Luna in forum 1.x Help
    Replies: 1
    Last Post: May 12, 2016, 6:34 PM
  2. Issue with Direct method called via Javascript
    By simonespagna in forum 2.x Help
    Replies: 1
    Last Post: Feb 22, 2015, 12:29 AM
  3. Replies: 3
    Last Post: Sep 26, 2014, 7:32 PM
  4. Replies: 2
    Last Post: Aug 30, 2012, 9:37 PM
  5. Replies: 2
    Last Post: Dec 08, 2011, 1:00 PM

Tags for this Thread

Posting Permissions