从数据库中查找出来的数据是多页的。查找出来的数据显示在GridView。当我使用AspNetPager进行分页设计时,
AspNetPager的上一页下一页不能进行跳转,页面总是停留在第1页上。如何解决?页面设计的代码如下:<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><!--为避免元素 meta 不包含在父元素中的错误,此句一定要在title之前 !-->
</head><body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div id="leftDiv" >
<asp:UpdatePanel ID="searchPanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text=" 工程名称:">
</asp:Label><asp:TextBox ID="projectNameTxt" runat="server"></asp:TextBox>
<asp:Button ID="projectBtn" runat="server" Text="查找"/><br />
<br /> </ContentTemplate> </asp:UpdatePanel>
<asp:UpdatePanel ID="resultPanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
<ContentTemplate>
<asp:GridView ID="dataGridView" runat="server"
ondatabound="dataGridView_DataBound"
onrowdatabound="dataGridView_RowDataBound"></asp:GridView>
<webdiyer:aspnetpager id="netPager" runat="server" horizontalalign="Center" PagingButtonSpacing="8px"
onpagechanged="AspNetPager1_PageChanged" ShowPageIndexBox="Always" SubmitButtonImageUrl="image/go.jpg"
ShowCustomInfoSection="Left" CustomInfoHTML="共%PageCount%页 %RecordCount%条记录"
SubmitButtonStyle="width:32px;height:22px;vertical-align:bottom" CustomInfoTextAlign="Left"
urlpaging="false" width="100%" LayoutType="Table" ShowNavigationToolTip="true" UrlPageIndexName="pageindex"
PageSize="12"></webdiyer:aspnetpager>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="projectBtn" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
AspNetPager的上一页下一页不能进行跳转,页面总是停留在第1页上。如何解决?页面设计的代码如下:<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><!--为避免元素 meta 不包含在父元素中的错误,此句一定要在title之前 !-->
</head><body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div id="leftDiv" >
<asp:UpdatePanel ID="searchPanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text=" 工程名称:">
</asp:Label><asp:TextBox ID="projectNameTxt" runat="server"></asp:TextBox>
<asp:Button ID="projectBtn" runat="server" Text="查找"/><br />
<br /> </ContentTemplate> </asp:UpdatePanel>
<asp:UpdatePanel ID="resultPanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
<ContentTemplate>
<asp:GridView ID="dataGridView" runat="server"
ondatabound="dataGridView_DataBound"
onrowdatabound="dataGridView_RowDataBound"></asp:GridView>
<webdiyer:aspnetpager id="netPager" runat="server" horizontalalign="Center" PagingButtonSpacing="8px"
onpagechanged="AspNetPager1_PageChanged" ShowPageIndexBox="Always" SubmitButtonImageUrl="image/go.jpg"
ShowCustomInfoSection="Left" CustomInfoHTML="共%PageCount%页 %RecordCount%条记录"
SubmitButtonStyle="width:32px;height:22px;vertical-align:bottom" CustomInfoTextAlign="Left"
urlpaging="false" width="100%" LayoutType="Table" ShowNavigationToolTip="true" UrlPageIndexName="pageindex"
PageSize="12"></webdiyer:aspnetpager>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="projectBtn" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
onpagechanging="anPager_PageChanging" UrlPaging="True"
ShowCustomInfoSection="Left" Width="650px">
</webdiyer:AspNetPager>protected void anPager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
this.anPager.CurrentPageIndex = e.NewPageIndex;
bind();
}
应该是用PageChanged事件,PageChanging事件是以前版本的。protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
//代码
}去掉:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="projectBtn" EventName="Click" />
</Triggers>
<asp:AsyncPostBackTrigger ControlID="projectBtn" EventName="Click" />
</Triggers>
部分的代码目的如下:当点击projectBtn时,从数据库中查找结果,并将第1页的结果显示在GridView中。当用户点击分页组件AspNetPager时,将分页数据再显示在GridView中。如果去除Triggers,就不能接受到我另外一个UpdatePanel中的事件了。我想程序能正确运行,是不是AspNetPager与UpdatePanel结合使用时,有什么注意点
<asp:UpdatePanel ID="searchPanel" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text=" 工程名称:">
</asp:Label> <asp:TextBox ID="projectNameTxt" runat="server"> </asp:TextBox>
<asp:Button ID="projectBtn" runat="server" Text="查找" OnClick="projectBtn_Click"/> <br />
<br />
<asp:GridView ID="dataGridView" runat="server"
ondatabound="dataGridView_DataBound"
onrowdatabound="dataGridView_RowDataBound"> </asp:GridView>
<webdiyer:aspnetpager id="netPager" runat="server" horizontalalign="Center" PagingButtonSpacing="8px"
onpagechanged="AspNetPager1_PageChanged" ShowPageIndexBox="Always" SubmitButtonImageUrl="image/go.jpg"
ShowCustomInfoSection="Left" CustomInfoHTML="共%PageCount%页 %RecordCount%条记录"
SubmitButtonStyle="width:32px;height:22px;vertical-align:bottom" CustomInfoTextAlign="Left"
urlpaging="false" width="100%" LayoutType="Table" ShowNavigationToolTip="true" UrlPageIndexName="pageindex"
PageSize="12"> </webdiyer:aspnetpager>
</ContentTemplate></asp:UpdatePanel>
</div>