Home All Groups Group Topic Archive Search About

DataView, DataGrid and IsPostBack

Author
6 Jan 2006 2:34 PM
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,

--
Sean

Author
6 Jan 2006 3:13 PM
Remy
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
Are all your drivers up to date? click for free checkup

Author
10 Jan 2006 2:33 PM
Fao, Sean
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
Author
10 Jan 2006 6:21 PM
Remy
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.
Author
6 Jan 2006 5:00 PM
S. Justin Gengo
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
<enceladus***@yahoo.com> wrote in message
Show quoteHide quote
news:1136558080.753187.62840@g14g2000cwa.googlegroups.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
>
Author
10 Jan 2006 2:35 PM
Fao, Sean
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

Bookmark and Share