利用 SqlDataSource进行自定义分页
来源:互联网 发布:熊片数据库 迅雷下载 编辑:程序博客网 时间:2024/03/29 01:01
<table width="100%">
<tr>
<td style="text-align: center">
第<asp:Label ID="LabelCurrentPage" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>页
/共<asp:Label ID="lblPageCount" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount %>' />页
<% //首页/上一页 %>
<% if (this.GVDept.PageIndex <= 0){ %>
<asp:LinkButton ID="LinkButton1" runat="server" Enabled="false" Text="首页" />
<asp:LinkButton ID="LinkButton2" runat="server" Enabled="false" Text="上一页" />
<% }else { %>
<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandArgument="First" CommandName="Page" Text="首页" />
<asp:LinkButton ID="LinkButton4" runat="server" CausesValidation="False" CommandArgument="Prev" CommandName="Page" Text="上一页" />
<% } %>
<% //下一页/尾页 %>
<% if (this.GVDept.PageIndex >= GVDept.PageCount - 1){ %>
<asp:LinkButton ID="LinkButton5" runat="server" Enabled="false" Text="下一页" />
<asp:LinkButton ID="LinkButton6" runat="server" Enabled="false" Text="尾页" />
<% } else { %>
<asp:LinkButton ID="LinkButton7" runat="server" CausesValidation="False" CommandArgument="Next" CommandName="Page" Text="下一页" />
<asp:LinkButton ID="LinkButton8" runat="server" CausesValidation="False" CommandArgument="Last" CommandName="Page" Text="尾页" />
<% } %>
</td>
</tr>
</table>
/// <summary>
/// 点击页码
/// </summary>
private void pageChanging(GridView gv, int pn, int pc)
{
int newPageIndex = pn;
newPageIndex = newPageIndex >= pc ? pc - 1 : newPageIndex;
newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
gv.PageIndex = newPageIndex;
//判断并取得当前要显示的页号
string pageno = (string)Request.QueryString["pageno"];
string pagecount = (string)Request.QueryString["pagecount"];
SqlConnection pageChageConn = DeptConnection.getConnection();
SqlCommand pageChageCmd = new SqlCommand("bmPageChage", pageChageConn);
pageChageCmd.CommandType = CommandType.StoredProcedure;
if (!string.IsNullOrEmpty(pageno) && !string.IsNullOrEmpty(pagecount))
{
pageChageCmd.Parameters.Add("@StartRowIndex", SqlDbType.Int, 4);
pageChageCmd.Parameters["@StartRowIndex"].Value = (Convert.ToInt32(pageno) - 1) * GVDept.PageSize;
pageChageCmd.Parameters.Add("@PageSize", SqlDbType.Int, 4);
pageChageCmd.Parameters["@PageSize"].Value = GVDept.PageSize;
}
try
{
pageChageConn.Open();
pageChageCmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(pageChageCmd);
DataSet ds = new DataSet();
da.Fill(ds, "Dept");
//绑定gridview
GVDept.DataSource = ds.Tables["Dept"].DefaultView;
GVDept.DataBind();
}
catch
{
}
finally
{
pageChageCmd.Dispose();
pageChageConn.Close();
}
}
protected void GVDept_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//点击分页按钮的事件
//点击分页按钮的事件
GridView theGrid = sender as GridView;
pageChanging(theGrid, e.NewPageIndex, theGrid.PageCount);
GVDept.PageIndex = e.NewPageIndex;
gvListBind();
}
- 利用 SqlDataSource进行自定义分页
- 自定义SqlDataSource
- GridView + SqlDataSource + 分页+ 搜索
- 利用ListView进行分页
- 利用DB2进行分页
- 利用angularjs进行分页
- 利用bootstrap进行分页
- 利用PageDataSource进行DataList分页
- 利用存储过程进行分页
- 利用PagedDataSource 对象进行分页
- 利用pagehelper进行分页查询
- 利用ListView自定义高效分页
- 利用动画进行自定义dialog
- AspNetPager+GridView+SqlDataSource实现分页效果
- SqlDataSource
- 利用JScript对长篇文章进行分页
- 利用sql对数据库进行分页
- 利用Grid组件进行分页的基础
- Adobe Flex最佳学习路线
- Java Eclipse 国际化
- 堆栈——Windows核心编程学习手札之十八
- 提出问题有时候比解决问题更难。
- 指定页面内容的打印
- 利用 SqlDataSource进行自定义分页
- 『转贴』do...while(0)的妙用
- C/C++中的日期和时间
- WinCE SMS Send
- DataList中的CheckBox利用 javaScript实现全选
- shark工作流的流程创建和持久化
- 如何做一名成功的科研工作者
- 用EXCEL导入试题
- 事务处理在vb.net中的应用2