469,348 Members | 1,265 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,348 developers. It's quick & easy.

DataView, DataGrid and IsPostBack

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,

--
Sean

Jan 6 '06 #1
5 3784
There are only two things you could do to solve this:

1) Save to and retrieve the dataview from a session variable, but do you
really want to save the DataView in memory between postbacks? If you have a
lot of users then this solution could use up a lot of memory.

2) Store in and retrieve the dataview from the client side viewstate. But if
the dataview is large this could put a large delay between postbacks into
the application.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
<en**********@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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,

--
Sean

Jan 6 '06 #2
Looking at you code, it looks like you already do cache the
ListAllViewableAuthors. Since you do that, it's not much of an overhead
to just assign it everytime the page loads.
This is something I've seen done on other pages too, either cache it or
some people tend to stick it into the session or even the viewstate.
But if you do that you really need to know what you are doing. If the
list gets big neither viewstate or session is the place to go.

Cheers

Remy

Jan 7 '06 #3
Remy wrote:
Looking at you code, it looks like you already do cache the
ListAllViewableAuthors. Since you do that, it's not much of an overhead
to just assign it everytime the page loads.
This is something I've seen done on other pages too, either cache it or
some people tend to stick it into the session or even the viewstate.
But if you do that you really need to know what you are doing. If the
list gets big neither viewstate or session is the place to go.


That's good to know. I wasn't really too sure about the overhead
involved with caching. I'm glad to hear that it's little because this
DataTable could actually grow quite large.

Thank you for your feedback,

--
Sean

Jan 10 '06 #4
S. Justin Gengo wrote:
There are only two things you could do to solve this:

1) Save to and retrieve the dataview from a session variable, but do you
really want to save the DataView in memory between postbacks? If you have a
lot of users then this solution could use up a lot of memory.

2) Store in and retrieve the dataview from the client side viewstate. But if
the dataview is large this could put a large delay between postbacks into
the application.


The DataView could potentially grow quite large. I think caching is my
best answer. I was kind of hoping that I was missing something that
should have been obvious.

Thank you for your help,

--
Sean

Jan 10 '06 #5
My point was that you already cache it, but you do not assign it to the
ListView everytime. If it grows too big, then maybe caching is not a
good option anymore and the only way left is to get it everytime from
the db.
This really depends on your requirements. If speed is the most
important thing, then cache it and get an appropriate box. If you have
to balance it, then I would suggest you only cache lists up to a
certain size and get the big ones directly.

Jan 10 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Arthur Dzhelali | last post: by
4 posts views Thread by Martin Schmid | last post: by
2 posts views Thread by Patrick Olurotimi Ige | last post: by
1 post views Thread by troyblakely | last post: by
13 posts views Thread by Steve | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.