Hello everybody, I got myself a strange problem
I have a DataGrid in the page, nothing special about it, only it connects datasource programatically and it supports paging.y. So the code is something like this
private void Page_Load(object sender, System.EventArgs e
if (!IsPostBack
GridBind()
private void GridBind(
myGrid..DataSource = GetSomeDataSource()
myGrid.DataBind()
private void PageChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e
myGrid.CurrentPageIndex = e.NewPageIndex
BindData()
This worked perfectly OK. Then I decided to try also to create grid columns dynamically. So I set the AutoGenerateColumns property to false. I changed the code, so it would create some columns like this
private void Page_Load(object sender, System.EventArgs e
AddSomeColumnsToGrid();
if (!IsPostBack
GridBind()
Now when I load the page for the 1st time, everything is OK. When I want to go to another page grid mystically disappears. I tried to debug the page setting breakpoint inside the PageChanged event and I never got there
Being desperate I tried everything possible then I came to something like this
private void Page_Load(object sender, System.EventArgs e
AddSomeColumnsToGrid();
//if (!IsPostBack
GridBind()
and it worked. But now I am creating dataset 2 times in postback (supposing it's the page changed event)
Am I doing anything wrong? Because I really don't know how to solve this problem. Any helps would be very appreciated. 4 1409
I made some errors in the first source code, it should be this
private void Page_Load(object sender, System.EventArgs e
if (!IsPostBack
GridBind()
private void GridBind(
myGrid.DataSource = GetSomeDataSource()
myGrid.DataBind()
private void PageChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e
myGrid.CurrentPageIndex = e.NewPageIndex
GridBind()
I made some errors in the first source code, it should be this
private void Page_Load(object sender, System.EventArgs e
if (!IsPostBack
GridBind()
private void GridBind(
myGrid.DataSource = GetSomeDataSource()
myGrid.DataBind()
private void PageChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e
myGrid.CurrentPageIndex = e.NewPageIndex
GridBind()
Add the AddSomeColumnsToGrid() method to the GridBind method. That way, any time you are going to bind the grid you know you have the columns.
I tried what you suggested, but the problem stays. Let's revisit the code once more (as you proposed):
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
GridBind();
}
private void GridBind()
{
AddSomeColumnsToGrid();
myGrid.DataSource = GetSomeDataSource();
myGrid.DataBind();
}
private void PageChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
myGrid.CurrentPageIndex = e.NewPageIndex;
GridBind();
}
Again it works OK when the page is loading for the 1st time. When I try to get another page, grid is gone. Debugging the project I found out that the execution never reaches the PageChanged handler. That is what confuses me mostly.
Because when I comment the line in Page_load like this:
private void Page_Load(object sender, System.EventArgs e)
{
// if (!IsPostBack)
GridBind();
}
it works. But now, unfortunately, the grid shows 2 copies of columns, logically, because I added them twice.
Resolution - the biggest problem as I see it is, that the execution is not passed to the handler of PageChanged event when postback occures, when I hit page number at the bottom of the grid.
This is pretty weird, I know. But that is why the solution is not easy to find in ANY help. Thanks in advance for further suggestions. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: RJN |
last post by:
Hi
Sorry for posting again.
I have a datagrid which is put inside a div tag to make it scrollable. I
need to page the datagrid. The page numbers appear at the bottom of the
datagrid and has...
|
by: Shawn |
last post by:
Hi.
I already have a datagrid where I'm using paging. I have a stored procedure
that fills a temp table with 200-500 rows and then sends back 10 records at
the time. When I go to page 2 the SP...
|
by: Axel Dahmen |
last post by:
Hi,
I'm using a DataGrid control to show a table's content with paging. For
navigation through the pages I'm using the DataGrid's intrinsic navigation
section.
My problem: The DataGrid...
|
by: tshad |
last post by:
Is there a way to carry data that I have already read from the datagrid from
page to page?
I am looking at my Datagrid that I page through and when the user says get
the next page, I have to go...
|
by: Pat |
last post by:
I have 3 Datagrid nested.
Master
Details
Child
The master has paging (And i'm using the paging inbuilt in the Datagrid)
in the Master DataGrid you select a linkbutton(using commandname) and it...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |