E
enceladus311
I'm trying to find a way to keep from having to fill a DataView after
every PostBack to a page. Basically, the design is that I have a
DataView that I fill, which I then set as the DataSource to a DataGrid
on my page. This works well, however, like I said, I would like to
keep from having to fill the DataView on each PostBack. So, naturally,
what I did was checked whether or not the request was a PostBack by
checking the IsPostBack property. Sounds great, but it broke the
sorting and paging (probably other things) on my DataGrid. For
example, when I click on a column to sort by, the DataGrid disappears.
I did some quick debugging and added a watch and realized that my
problem comes from the fact that my DataView does not retain its value
between posts (at the beginning of each page load (between post backs)
the DataView contains an unknown (uninitialized) value).
<code>
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
if (Cache["ListAllViewableAuthors"] == null)
Cache["ListAllViewableAuthors"] =
DataLayer.Authors.ListAllViewableAuthors();
this.AuthorsDataView = new DataView((DataTable)
Cache["ListAllViewableAuthors"]);
this.AuthorsDataGrid.DataSource = this.AuthorsDataView;
this.AuthorsDataGrid.DataBind();
}
}
</code>
As you can see, I have seperated the database access layer and created
a static method to fill my DataView. But anyway, what is the proper
way to implement such a design so that I don't have to fill the
DataView on each post back?
Thank you in advance,
every PostBack to a page. Basically, the design is that I have a
DataView that I fill, which I then set as the DataSource to a DataGrid
on my page. This works well, however, like I said, I would like to
keep from having to fill the DataView on each PostBack. So, naturally,
what I did was checked whether or not the request was a PostBack by
checking the IsPostBack property. Sounds great, but it broke the
sorting and paging (probably other things) on my DataGrid. For
example, when I click on a column to sort by, the DataGrid disappears.
I did some quick debugging and added a watch and realized that my
problem comes from the fact that my DataView does not retain its value
between posts (at the beginning of each page load (between post backs)
the DataView contains an unknown (uninitialized) value).
<code>
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
if (Cache["ListAllViewableAuthors"] == null)
Cache["ListAllViewableAuthors"] =
DataLayer.Authors.ListAllViewableAuthors();
this.AuthorsDataView = new DataView((DataTable)
Cache["ListAllViewableAuthors"]);
this.AuthorsDataGrid.DataSource = this.AuthorsDataView;
this.AuthorsDataGrid.DataBind();
}
}
</code>
As you can see, I have seperated the database access layer and created
a static method to fill my DataView. But anyway, what is the proper
way to implement such a design so that I don't have to fill the
DataView on each post back?
Thank you in advance,