Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Paging-enabled GridView disappears at postback

Reply
Thread Tools

Paging-enabled GridView disappears at postback

 
 
antonyliu2002@yahoo.com
Guest
Posts: n/a
 
      01-31-2007
I've been googling for some time, and could not find the solution to
this problem.

I am testing the paging feature of gridview. I have a very simple web
form on which the user can select a few fields to be included in the
table, which is to be bound to the gridview.

The web form looks like so (Don't worry about the stupidity of this
web form for now.):

Check stuffs you wanna include in the table:

[] Customer ID
[] Customer Last Name
[] Customer First Name
[] Customer Email
[] Customer Phone

[Click this button to show the table]

[---- the paging-enabled gridview is right here ------]

The gridview is declared like so:

<asp:GridView ID="GridView1"
EnableViewState="true"
EnableSortingAndPagingCallbacks="true"
DataSourceID="SqlDataSource1"
runat="server"
AllowPaging="True"
AllowSorting="true">
</asp:GridView>

In the code-behind (in C#), I pass the programmatically created SQL
select command to the SqlDataSource like so:

SqlDataSource1.SelectCommand = theSelectCommandCreatedOnTheFly;

Now, after the user clicks the button to create the customer report,
the gridview is populated with customer data with the expected fields.

But, when the paging index is clicked, the gridview disaapears. One
short note from a blog says that gridview will disappear between
postbacks. So, this might be the cause.

I guess I don't need to implement a GridView1_OnPageIndexChanging
method to handle the paging event since I don't think I am manually
binding the gridview to the dataset.

How do we handle this problem? Thanks.

 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      01-31-2007
On Jan 31, 4:49 am, "(E-Mail Removed)"
<(E-Mail Removed)> wrote:
> I've been googling for some time, and could not find the solution to
> this problem.
>
> I am testing the paging feature of gridview. I have a very simple web
> form on which the user can select a few fields to be included in the
> table, which is to be bound to the gridview.
>
> The web form looks like so (Don't worry about the stupidity of this
> web form for now.):
>
> Check stuffs you wanna include in the table:
>
> [] Customer ID
> [] Customer Last Name
> [] Customer First Name
> [] Customer Email
> [] Customer Phone
>
> [Click this button to show the table]
>
> [---- the paging-enabled gridview is right here ------]
>
> The gridview is declared like so:
>
> <asp:GridView ID="GridView1"
> EnableViewState="true"
> EnableSortingAndPagingCallbacks="true"
> DataSourceID="SqlDataSource1"
> runat="server"
> AllowPaging="True"
> AllowSorting="true">
> </asp:GridView>
>
> In the code-behind (in C#), I pass the programmatically created SQL
> select command to the SqlDataSource like so:
>
> SqlDataSource1.SelectCommand = theSelectCommandCreatedOnTheFly;
>
> Now, after the user clicks the button to create the customer report,
> the gridview is populated with customer data with the expected fields.
>
> But, when the paging index is clicked, the gridview disaapears. One
> short note from a blog says that gridview will disappear between
> postbacks. So, this might be the cause.
>
> I guess I don't need to implement a GridView1_OnPageIndexChanging
> method to handle the paging event since I don't think I am manually
> binding the gridview to the dataset.
>
> How do we handle this problem? Thanks.


sound's like you don't bind your grid after postback

Can you please tell us where you do bind it (sample code)?

 
Reply With Quote
 
 
 
 
antonyliu2002@yahoo.com
Guest
Posts: n/a
 
      01-31-2007
On Jan 31, 1:36 am, "Alexey Smirnov" <(E-Mail Removed)> wrote:
> On Jan 31, 4:49 am, "(E-Mail Removed)">
>
> <(E-Mail Removed)> wrote:
> > I've been googling for some time, and could not find the solution to
> > this problem.

>
> > I am testing the paging feature of gridview. I have a very simple web
> > form on which the user can select a few fields to be included in the
> > table, which is to be bound to the gridview.

>
> > The web form looks like so (Don't worry about the stupidity of this
> > web form for now.):

>
> > Check stuffs you wanna include in the table:

>
> > [] Customer ID
> > [] Customer Last Name
> > [] Customer First Name
> > [] Customer Email
> > [] Customer Phone

>
> > [Click this button to show the table]

>
> > [---- the paging-enabled gridview is right here ------]

>
> > The gridview is declared like so:

>
> > <asp:GridView ID="GridView1"
> > EnableViewState="true"
> > EnableSortingAndPagingCallbacks="true"
> > DataSourceID="SqlDataSource1"
> > runat="server"
> > AllowPaging="True"
> > AllowSorting="true">
> > </asp:GridView>

>
> > In the code-behind (in C#), I pass the programmatically created SQL
> > select command to the SqlDataSource like so:

>
> > SqlDataSource1.SelectCommand = theSelectCommandCreatedOnTheFly;

>
> > Now, after the user clicks the button to create the customer report,
> > the gridview is populated with customer data with the expected fields.

>
> > But, when the paging index is clicked, the gridview disaapears. One
> > short note from a blog says that gridview will disappear between
> > postbacks. So, this might be the cause.

>
> > I guess I don't need to implement a GridView1_OnPageIndexChanging
> > method to handle the paging event since I don't think I am manually
> > binding the gridview to the dataset.

>
> > How do we handle this problem? Thanks.

>
> sound's like you don't bind your grid after postback
>
> Can you please tell us where you do bind it (sample code)?- Hide quoted text -
>


OK, thanks a lot. I actually mentioned it in my original post. I have
a SqlDataSource control and the GridView is bound to it in the
declaration. I repeat the GridView declaration here:

<asp:GridView ID="GridView1"
EnableViewState="true"
EnableSortingAndPagingCallbacks="true"
DataSourceID="SqlDataSource1"
runat="server"
AllowPaging="True"
AllowSorting="true">
</asp:GridView>

In the code behind, the only thing I programmatically do is to assign
the select command to SqlDataSource1 like so:

SqlDataSource1.SelectCommand = theSelectCommandCreatedOnTheFly;

In other words, I don't have anything in code-behind that mannually
binds the data to the gridview, nothing in my code-behind is like
getting a DataSet, SqlDataAdapter, Fills the DataSet, DataBind the
GridView.

That's why I also mentioned that I probably don't have to implement a
method GridView1_OnPageIndexChanging since I am not manually binding
the GridView. I might be wrong, but please advise. Thanks again.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TemplateField in 2.0 // Disappears on Postback when TemplateField is added thru code sloan ASP .Net 2 10-17-2007 09:08 AM
Dynamically created control disappears after postback. Sami Rehman ASP .Net 1 09-03-2007 10:51 AM
Controls added dynamically disappears after postback Ryu ASP .Net 1 08-18-2004 05:17 AM
User Control Disappears After PostBack - Why? Guadala Harry ASP .Net 3 07-01-2004 11:09 PM
dataset disappears on postback =?Utf-8?B?amhpbGw=?= ASP .Net 3 05-21-2004 01:11 AM



Advertisments