gridview 万能分页代码
2012-09-15 19:17
281 查看
实现如下图片的分页:第【】页,共【】页,首页,上一页,下一页,末页 跳到某页;图片在最下面;gv里面的模板PagerTemplate复制到你的gv对应位置,然后在
protected
void gvgetall_PageIndexChanging(object sender,
GridViewPageEventArgs e)事件里面写.cs里代码就可以实现。
<asp:GridView ID="gvgetall" runat="server" AllowSorting="True" AutoGenerateColumns="False"
Width="100%" OnRowCommand="gvgetall_RowCommand" EmptyDataText="没有任何数据可以显示" AllowPaging="True"
OnPageIndexChanging="gvgetall_PageIndexChanging" PageSize="2" OnSorting="gvgetall_Sorting"
OnRowCreated="gvgetall_RowCreated" OnRowDataBound="gvgetall_RowDataBound">
<Columns>
<asp:BoundField DataField="En_id" HeaderText="编号" Visible="False">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField HeaderText="企业名称" SortExpression="name">
<ItemTemplate>
<asp:LinkButton ID="btnupdate" CommandName="update" CommandArgument='<%#Eval("ID") %>'
runat="server" Text='<%# trimFieldLength(Eval("name").ToString())%>' ForeColor="blue" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<FooterTemplate>
RETGRYTRYTYGTY
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="WEBSITE" HeaderText="企业网址">
<ItemTemplate>
<asp:Label ID="lbweb" Visible="false" runat="server" Text='<%# trimFieldLength1(Eval("WEBSITE").ToString())%>'></asp:Label>
<a href='<%=ViewState["web"]%>' target="_blank">
<%# trimFieldLength1(Eval("WEBSITE").ToString())%>
</a>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="address" HeaderText="企业地址" SortExpression="address">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
<PagerStyle CssClass="cssPager" />
<AlternatingRowStyle BackColor="#E2F8FF"></AlternatingRowStyle>
<HeaderStyle HorizontalAlign="Center" BackColor="#99CCFF"></HeaderStyle>
<PagerTemplate>
<table>
<tr>
<td style="text-align: right">
第<asp:Label ID="lblPageIndex" runat="server" Text="<%#((GridView)Container.Parent.Parent).PageIndex + 1 %>"></asp:Label>页
共<asp:Label ID="lblPageCount" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageCount %>"></asp:Label>页
<asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False" CommandArgument="First"
CommandName="Page" Text="首页" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>"></asp:LinkButton>
<asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False" CommandArgument="Prev"
CommandName="Page" Text="上一页" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>"></asp:LinkButton>
<asp:LinkButton ID="btnNext" runat="server" CausesValidation="False" CommandArgument="Next"
CommandName="Page" Text="下一页" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>"></asp:LinkButton>
<asp:LinkButton ID="btnLast" runat="server" CausesValidation="False" CommandArgument="Last"
CommandName="Page" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>"
Text="尾页"></asp:LinkButton>
<asp:TextBox ID="txtNewPageIndex" runat="server" onkeyup="value=value.replace(/[^\d]/g,'') "
Text="<%# ((GridView)Container.Parent.Parent).PageIndex + 1%>" Width="20px"></asp:TextBox>
<asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-1"
CommandName="Page" Text="GO"></asp:LinkButton>
</td>
</tr>
</table>
</PagerTemplate>
</asp:GridView>
.cs
protected void gvgetall_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView gvw = (GridView)sender;//当前实例
if (e.NewPageIndex < 0)
{
TextBox pageNum = (TextBox)gvw.BottomPagerRow.FindControl("txtNewPageIndex");
int Pa = int.Parse(pageNum.Text);
if (Pa <= 0)
{
gvw.PageIndex = 0;
}
else
{
gvw.PageIndex = Pa - 1;
}
}
else
{
gvw.PageIndex = e.NewPageIndex;
}
bind();
}
protected
void gvgetall_PageIndexChanging(object sender,
GridViewPageEventArgs e)事件里面写.cs里代码就可以实现。
<asp:GridView ID="gvgetall" runat="server" AllowSorting="True" AutoGenerateColumns="False"
Width="100%" OnRowCommand="gvgetall_RowCommand" EmptyDataText="没有任何数据可以显示" AllowPaging="True"
OnPageIndexChanging="gvgetall_PageIndexChanging" PageSize="2" OnSorting="gvgetall_Sorting"
OnRowCreated="gvgetall_RowCreated" OnRowDataBound="gvgetall_RowDataBound">
<Columns>
<asp:BoundField DataField="En_id" HeaderText="编号" Visible="False">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField HeaderText="企业名称" SortExpression="name">
<ItemTemplate>
<asp:LinkButton ID="btnupdate" CommandName="update" CommandArgument='<%#Eval("ID") %>'
runat="server" Text='<%# trimFieldLength(Eval("name").ToString())%>' ForeColor="blue" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<FooterTemplate>
RETGRYTRYTYGTY
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="WEBSITE" HeaderText="企业网址">
<ItemTemplate>
<asp:Label ID="lbweb" Visible="false" runat="server" Text='<%# trimFieldLength1(Eval("WEBSITE").ToString())%>'></asp:Label>
<a href='<%=ViewState["web"]%>' target="_blank">
<%# trimFieldLength1(Eval("WEBSITE").ToString())%>
</a>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="address" HeaderText="企业地址" SortExpression="address">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
<PagerStyle CssClass="cssPager" />
<AlternatingRowStyle BackColor="#E2F8FF"></AlternatingRowStyle>
<HeaderStyle HorizontalAlign="Center" BackColor="#99CCFF"></HeaderStyle>
<PagerTemplate>
<table>
<tr>
<td style="text-align: right">
第<asp:Label ID="lblPageIndex" runat="server" Text="<%#((GridView)Container.Parent.Parent).PageIndex + 1 %>"></asp:Label>页
共<asp:Label ID="lblPageCount" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageCount %>"></asp:Label>页
<asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False" CommandArgument="First"
CommandName="Page" Text="首页" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>"></asp:LinkButton>
<asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False" CommandArgument="Prev"
CommandName="Page" Text="上一页" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>"></asp:LinkButton>
<asp:LinkButton ID="btnNext" runat="server" CausesValidation="False" CommandArgument="Next"
CommandName="Page" Text="下一页" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>"></asp:LinkButton>
<asp:LinkButton ID="btnLast" runat="server" CausesValidation="False" CommandArgument="Last"
CommandName="Page" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>"
Text="尾页"></asp:LinkButton>
<asp:TextBox ID="txtNewPageIndex" runat="server" onkeyup="value=value.replace(/[^\d]/g,'') "
Text="<%# ((GridView)Container.Parent.Parent).PageIndex + 1%>" Width="20px"></asp:TextBox>
<asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-1"
CommandName="Page" Text="GO"></asp:LinkButton>
</td>
</tr>
</table>
</PagerTemplate>
</asp:GridView>
.cs
protected void gvgetall_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView gvw = (GridView)sender;//当前实例
if (e.NewPageIndex < 0)
{
TextBox pageNum = (TextBox)gvw.BottomPagerRow.FindControl("txtNewPageIndex");
int Pa = int.Parse(pageNum.Text);
if (Pa <= 0)
{
gvw.PageIndex = 0;
}
else
{
gvw.PageIndex = Pa - 1;
}
}
else
{
gvw.PageIndex = e.NewPageIndex;
}
bind();
}
相关文章推荐
- GridView分页代码简单万能实用
- GridView分页代码简单万能实用
- gridview 万能分页代码
- GridView万能分页代码
- 万能简单GridView分页代码
- 利用jQuery 实现GridView异步排序、分页的代码
- 1.GridView无代码分页排序 GridView选中,编辑,取消,删除:
- GridView无代码分页排序
- GridView 手动分页代码
- GridView支持分页的自动编号代码
- GridView无代码分页排序
- gridview 实现自定义分页、排序、查询、添加、编辑、多选删除 之代码规范
- GridView支持分页的自动编号代码
- GridView自带分页功能代码(页面)
- 利用jQuery 实现GridView异步排序、分页的代码
- 为GridView控件添加分页导航条形式代码
- .net GridView分页模板的实例代码
- 使用GridView自带分页的代码
- 2013-02-26 18:29 Gridview动态绑定mysql以及分页显示代码
- Yii2.0小部件GridView(两表联查/搜索/分页)功能的实现代码