2

我有一个数据绑定asp:GridView

<asp:GridView ID="gridUsers" runat="server" ShowHeaderWhenEmpty="True" Width="100%" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
   <Columns>
       <asp:BoundField DataField="UserGUID" HeaderText="UserGUID" SortExpression="UserGUID" Visible="False" />
       <asp:HyperLinkField DataNavigateUrlFields="UserGUID" DataNavigateUrlFormatString="~\UserManagement\UserProperties.aspx?userGuid={0}" DataTextField="Username" HeaderText="User name" SortExpression="Username" />
       <asp:BoundField DataField="Fullname" HeaderText="Full name" SortExpression="Fullname" />
       <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description"/>
       <asp:BoundField DataField="Email" HeaderText="E-mail" SortExpression="Email"/>
       <asp:BoundField DataField="IsActive" HeaderText="Active" SortExpression="IsActive" Visible="False" />
       <asp:BoundField DataField="AuthenticationType" HeaderText="Account type" SortExpression="AuthenticationType" />
    </Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db %>"
    SelectCommand="SELECT UserGUID, Username, Fullname, Description, Email, IsActive, AuthenticationType FROM Users WHERE IsActive = 1 ORDER BY Username">
</asp:SqlDataSource>

使用相应的代码隐藏:

public partial class FooItToHoo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
}

当我浏览到页面时,网格可以正确填充:

但是当我返回然后前进(或导航到另一个页面并返回)时,网格是空的:

如果我按 F5,页面会刷新,并且网格存在并填充:

我究竟做错了什么?


更新:我的页面的初始请求没有被缓存;服务器的响应是:

HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Wed, 13 Jun 2012 13:16:32 GMT
X-AspNet-Version: 4.0.30319
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 53219
Connection: Close

在提供htmlasp:GridView中呈现内容:

导航离开然后返回,没有服务器请求;所以页面必须从缓存中提供。

ASP.net 在做什么,呈现的页面包含内容,但“缓存”页面不包含内容?

4

2 回答 2

0

This seems to be cache problem. remove cache from your browser and use below code on your page to prevent your page from being caching.

The Meta tags:

 <meta http-equiv="Expires" CONTENT="0">
 <meta http-equiv="Cache-Control" CONTENT="no-cache">
 <meta http-equiv="Pragma" CONTENT="no-cache">

And the code:

Response.ExpiresAbsolute = DateTime.Now;
Response.Expires = -1441;
Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "no-cache");
Response.AddHeader("Pragma", "no-store");
Response.AddHeader("cache-control", "no-cache");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoServerCaching();
于 2012-09-25T10:40:21.207 回答
0

网格显示为空的原因是,当您单击下一步按钮时,没有可用于与网格绑定的数据源。所以为此你需要

选择gridview->转到属性窗口->单击事件按钮

双击 pageindexchangeing 事件

并设置

Allowpaging=true对于网格视图

在 pageindex 更改事件中编写以下代码

gridview1.pageindex=e.newpageindex;
//gridbindingcode

gridview1.databind();
于 2012-09-24T12:10:56.053 回答