<pagertemplate>
<table width="100%">
<tr>
<td style="text-align:right">
第<asp:Label id="lblPageIndex" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页
共/<asp:Label id="lblPageCount" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageCount %>' />页
<asp:linkbutton id="btnFirst" runat="server" causesvalidation="False" commandargument="First" commandname="Page" text="首页" />
<asp:linkbutton id="btnPrev" runat="server" causesvalidation="False" commandargument="Prev" commandname="Page" text="上一页" />
<asp:linkbutton id="btnNext" runat="server" causesvalidation="False" commandargument="Next" commandname="Page" text="下一页" />
<asp:linkbutton id="btnLast" runat="server" causesvalidation="False" commandargument="Last" commandname="Page" text="尾页" />
<asp:textbox id="txtNewPageIndex" runat="server" width="20px" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
<asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" /><!-- here set the CommandArgument of the Go Button to '-1' as the flag -->
</td>
</tr>
</table>
</pagertemplate> protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView theGrid = sender as GridView; // refer to the GridView
int newPageIndex = 0; if (-2 == e.NewPageIndex) { // when click the "GO" Button
TextBox txtNewPageIndex = null;
//GridViewRow pagerRow = theGrid.Controls[0].Controls[theGrid.Controls[0].Controls.Count - 1] as GridViewRow; // refer to PagerTemplate
GridViewRow pagerRow = theGrid.BottomPagerRow; //GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow
//updated at 2006年6月21日3:15:33 if (null != pagerRow) {
txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox; // refer to the TextBox with the NewPageIndex value
} if (null != txtNewPageIndex) {
newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; // get the NewPageIndex
}
}
else { // when click the first, last, previous and next Button
newPageIndex = e.NewPageIndex;
} // check to prevent form the NewPageIndex out of the range
newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex; // specify the NewPageIndex
theGrid.PageIndex = newPageIndex;
//theGrid.PageIndex = e.NewPageIndex; // rebind the control
// in this case of retrieving the data using the xxxDataSoucr control,
// just do nothing, because the asp.net engine binds the data automatically theGrid.DataSource = DB.ODateSet;
theGrid.DataBind();
DB.free();
}这是网上一个分页例子,单步测试了,点击下一步都无法触发GridView1_PageIndexChanging事件,gridview是空白一片,各位帮帮忙吧,谢谢了!!
<table width="100%">
<tr>
<td style="text-align:right">
第<asp:Label id="lblPageIndex" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页
共/<asp:Label id="lblPageCount" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageCount %>' />页
<asp:linkbutton id="btnFirst" runat="server" causesvalidation="False" commandargument="First" commandname="Page" text="首页" />
<asp:linkbutton id="btnPrev" runat="server" causesvalidation="False" commandargument="Prev" commandname="Page" text="上一页" />
<asp:linkbutton id="btnNext" runat="server" causesvalidation="False" commandargument="Next" commandname="Page" text="下一页" />
<asp:linkbutton id="btnLast" runat="server" causesvalidation="False" commandargument="Last" commandname="Page" text="尾页" />
<asp:textbox id="txtNewPageIndex" runat="server" width="20px" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
<asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" /><!-- here set the CommandArgument of the Go Button to '-1' as the flag -->
</td>
</tr>
</table>
</pagertemplate> protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView theGrid = sender as GridView; // refer to the GridView
int newPageIndex = 0; if (-2 == e.NewPageIndex) { // when click the "GO" Button
TextBox txtNewPageIndex = null;
//GridViewRow pagerRow = theGrid.Controls[0].Controls[theGrid.Controls[0].Controls.Count - 1] as GridViewRow; // refer to PagerTemplate
GridViewRow pagerRow = theGrid.BottomPagerRow; //GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow
//updated at 2006年6月21日3:15:33 if (null != pagerRow) {
txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox; // refer to the TextBox with the NewPageIndex value
} if (null != txtNewPageIndex) {
newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; // get the NewPageIndex
}
}
else { // when click the first, last, previous and next Button
newPageIndex = e.NewPageIndex;
} // check to prevent form the NewPageIndex out of the range
newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex; // specify the NewPageIndex
theGrid.PageIndex = newPageIndex;
//theGrid.PageIndex = e.NewPageIndex; // rebind the control
// in this case of retrieving the data using the xxxDataSoucr control,
// just do nothing, because the asp.net engine binds the data automatically theGrid.DataSource = DB.ODateSet;
theGrid.DataBind();
DB.free();
}这是网上一个分页例子,单步测试了,点击下一步都无法触发GridView1_PageIndexChanging事件,gridview是空白一片,各位帮帮忙吧,谢谢了!!
解决方案 »
- webconfig中如何连接数据库?
- 看看这是用什么方法做的
- asp.net实现在线时时显示监控云台的监控图象
- 关于网页刷新的问题
- OnTextChanged,为什么没有触发呢?
- [简单问题]如何将TextBox中的内容转化为带html标记的内容?
- 下拉菜单,selectindex改变时,自动弹出新窗口,用RegisterClientScriptBlock方式,不能打开新窗口.请问原因.(有详细代码)
- 求教,关于数据库表生成xml文件节点的问题
- 这个筛选功能如何实现呀,请高手帮助,在线等
- 数据库里是bit类型的字段在c#里如何判断它是false or ture??在线等待
- 存放图片路径到ACCESS数据库并读取显示
- 急哭了!配置Web.Config时出现无法连接到 SQL Server 数据库的问题!!!
AllowPaging = true;
等等
还有什么可能导致 GridView1_PageIndexChanging事件无法触发呢??
<asp:linkbutton id="btnNext" runat="server" causesvalidation="False" commandargument="Next" commandname="Page" text="下一页" />
点击下一页,那个GridView1_PageIndexChanging事件无法激发
datasourceid="CustomersSource"
autogeneratecolumns="true"
emptydatatext="No data available."
allowpaging="true"
autogenerateeditbutton="true"
datakeynames="CustomerID"
onpageindexchanging="CustomersGridView_PageIndexChanging"
onrowcancelingedit="CustomersGridView_RowCancelingEdit"
runat="server">
都是自己拖上去的button?如果是这样的话应该不行吧因为如果使用了GridView自己的分页的话它便自动会有下一页,上一页的按钮在属性菜单里,PagerSettings设置
HorizontalAlign="Center" Width="980px" AutoGenerateColumns="False"
OnPageIndexChanging="GridView1_PageIndexChanging" Font-Size="Smaller"
PageSize="5" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None"
BorderWidth="1px" CssClass="tb_Inner" OnRowDataBound="GridView1_RowDataBound"
EmptyDataText="<center>没有搜索到任何记录,请重置搜索条件。</center>" ForeColor="Red"
EnableViewState="False" AllowPaging="True">这个我写了..,gridview一样是空白一片
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.datasource="数据源";
GridView1.DataBind();
}
{
if(!Page.IsPostBack)
{
DataGridDataBind();
}
}
//绑定数据
private void DataGridDataBind()
{
DataSet ds = GetCustomersData();
recordCount = ds.Tables[0].Rows.Count;
//获取当前的页数
pageCount = (int)Math.Ceiling( recordCount * 1.0 / PageSize);
//避免纪录从有到无时,并且已经进行过反页的情况下CurrentPageIndex > PageCount出错
if(recordCount ==0)
{
this.DataGrid1.CurrentPageIndex = 0;
}
else if(this.DataGrid1.CurrentPageIndex >= pageCount)
{
this.DataGrid1.CurrentPageIndex = pageCount - 1;
}
this.DataGrid1.DataSource = ds;
this.DataGrid1.DataBind();
NavigationStateChange();
}
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.datasource="数据源";
GridView1.DataBind();
}
这个方法行.