Apr 12, 2017, 11:49 AM
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
Thank you
Attachment 24925
Attachment 24930
Attachment 24931
Attachment 24932
Attachment 24933
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 :DThank you
Attachment 24925
Attachment 24930
Attachment 24931
Attachment 24932
Attachment 24933
Last edited by lokihnahta; May 03, 2017 at 4:07 AM.