GridView自定义分页实例详解(附demo源码下载)
更新时间:2021年9月22日 10:09 点击:1335
本文实例讲述了GridView自定义分页实现方法。分享给大家供大家参考,具体如下:
CSS样式
首先把CSS样式代码粘贴过来:
.gv { border: 1px solid #D7D7D7; font-size:12px; text-align:center; } .gvHeader { color: #3F6293; background-color: #F7F7F7; height: 24px; line-height: 24px; text-align: center; font-weight: normal; font-variant: normal; } .gvHeader th { font-weight: normal; font-variant: normal; } .gvRow, .gvAlternatingRow, .gvEditRow { line-height: 20px; text-align: center; padding: 2px; height: 20px; } .gvAlternatingRow { background-color: #F5FBFF; } .gvEditRow { background-color: #FAF9DD; } .gvEditRow input { background-color: #FFFFFF; width: 80px; } .gvEditRow .gvOrderId input, .gvEditRow .gvOrderId { width: 30px; } .gvEditRow .checkBox input, .gvEditRow .checkBox { width: auto; } .gvCommandField { text-align: center; width: 130px; } .gvLeftField { text-align: left; padding-left: 10px; } .gvBtAField { text-align: center; width: 130px; } .gvCommandField input { background-image: url(../Images/gvCommandFieldABg.jpg); background-repeat: no-repeat; line-height: 23px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; width: 50px; height: 23px; margin-right: 3px; margin-left: 3px; text-indent: 10px; } .gvPage { padding-left: 15px; font-size: 18px; color: #333333; font-family: Arial, Helvetica, sans-serif; } .gvPage a { display: block; text-decoration: none; padding-top: 2px; padding-right: 5px; padding-bottom: 2px; padding-left: 5px; border: 1px solid #FFFFFF; float: left; font-size: 12px; font-weight: normal; } .gvPage a:hover { display: block; text-decoration: none; border: 1px solid #CCCCCC; }
GridView样式
根据上面列出的CSS样式样式名称,将他们分别加入网页GridView的不同标记中,举例如下:
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" CssClass="gvRow" /> <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" CssClass="gvHeader" /> <AlternatingRowStyle BackColor="#F7F7F7" CssClass="gvAlternatingRow" />
Pager分页模板
其中gridview下方的换页代码为:
<PagerTemplate> <table width="100%" style="font-size:12px;"> <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="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page" Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页</asp:LinkButton> <asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page" Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页</asp:LinkButton> <asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page" Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页</asp:LinkButton> <asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page" Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">尾页</asp:LinkButton> <asp:TextBox ID="txtNewPageIndex" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' Width="20px" AutoPostBack="true" ></asp:TextBox> <asp:LinkButton ID="btnGo" runat="server" CommandArgument="GO" CommandName="Page" Text="GO" OnClick="btnGo_Click"></asp:LinkButton> </td> </tr> </table> </PagerTemplate>
触发事件
方法btnGo_Click的定义如下所示:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; BindData(); } protected void btnGo_Click(object sender, EventArgs e) { if (((LinkButton)sender).CommandArgument.ToString().ToLower().Equals("go")) { GridViewRow gridViewRow = GridView1.BottomPagerRow; TextBox numBox = (TextBox)GridView1.BottomPagerRow.FindControl("txtNewPageIndex"); int inputNum = Convert.ToInt32(numBox.Text); GridView1.PageIndex = inputNum - 1; BindData(); } }
效果图展示及源码下载
完整实例代码点击此处本站下载。
希望本文所述对大家asp.net程序设计有所帮助。
相关文章
- 这篇文章主要介绍了C#实现3步手动建DataGridView的方法,实例分析了C#实现手动创建DataGridView的原理与技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了C#中DataGridView动态添加行及添加列的方法,涉及C#中DataGridView针对行与列动态操作的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
C#中datagridview使用tooltip控件显示单元格内容的方法
这篇文章主要介绍了C#中datagridview使用tooltip控件显示单元格内容的方法,实例分析了C#控件的相关使用技巧,需要的朋友可以参考下...2020-06-25- 这篇文章主要介绍了C#中GridView动态添加列的实现方法,涉及C#中GridView的相关使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
- 下面小编就为大家带来一篇浅析GridView中显示时间日期格式的问题。小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2021-09-22
- 这篇文章主要介绍了C#中DataGridView常用操作,以实例形式总结了DataGridView绑定下拉列表、设置默认值、判断复选框是否选中等技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
- Gridview的链接和删除点击提示有利于提醒用户确认下操作是否正确,以免造成不必要的损失,感兴趣的朋友可以参考下,希望对你有所帮助...2021-09-22
- 这个例子的功能是c#读取excel文件,大家可以参考使用...2020-06-25
实现DataGridView控件中CheckBox列的使用实例
最近做WindowsForms程序,使用DataGridView控件时,加了一列做选择用,发现CheckBox不能选中。搜索后,要实现DataGridView的CellContentClick事件,将代码贴一下...2021-09-22- 这篇文章主要介绍了c#中datagridview处理非绑定列的方法,实例分析了C#中datagridview的使用技巧,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了C#中改变DataGridView控件边框颜色的方法,默认的DataGridView边框颜色很丑,本文用编程方法实现修改DataGridView边框颜色,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了C#中DataGridView的样式设置方法,包括交替行颜色、单元格内容有效性检查、单元格的选择模式等,需要的朋友可以参考下...2020-06-25
在ASP.NET 2.0中操作数据之六十四:GridView批量添加数据
前面介绍了批量更新,批量删除数据,这篇文章主要介绍如何实现批量添加数据,当然为了保证数据的完整性,我们在做这些批量操作的时候,都使用了事务来实现。...2021-09-22.Net语言Smobiler开发利用Gridview控件设计较复杂的表单
这篇文章主要为大家详细介绍了.Net语言Smobiler开发利用Gridview控件设计较复杂的表单,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-22- 这篇文章主要是关于GridView使用的学习总结,需要的朋友可以参考下...2021-09-22
DevExpress实现GridView当无数据行时提示消息
这篇文章主要介绍了DevExpress实现GridView当无数据行时提示消息,需要的朋友可以参考下...2020-06-25Asp.net简单代码设置GridView自适应列宽不变形实现思路与代码
动态绑定的GridView由于列数不固定,而列又太多(博主做的这个项目有150个左右的字段),这样设置GridView固定宽度就不能满足需求了...2021-09-22C# 实现dataGridView选中一行右键出现菜单的示例代码
这篇文章主要介绍了C# 实现dataGridView选中一行右键出现菜单,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-11-03GridView导出Excel常见的5种文本格式 <font color=red>原创</font>
本文主要介绍GridView导出Excel常见的文本格式,以帮助开发人员做导出的Excel时避免出现文本格式不一致的问题。...2021-09-22- confirm用户确认删除是一个很实用的功能,比如可以防止用户误操作删除等等,感兴趣的朋友可以了解下,希望本文对你有所帮助,就当巩固知识了...2021-09-22