码迷,mamicode.com
首页 > 其他好文 > 详细

GridView分页(第一页、上一页、下一页、最后页、当前页数/总页数)

时间:2014-09-18 20:30:14      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   os   ar   div   art   sp   


bubuko.com,布布扣<PagerTemplate>
bubuko.com,布布扣                <table width="100%">
bubuko.com,布布扣                    <tr>
bubuko.com,布布扣                        <td width="75%">
bubuko.com,布布扣                            <asp:ImageButton ID="imgBtnFirst" runat="server" CommandArgument="First" CommandName="Page"
bubuko.com,布布扣                                ImageUrl="~/Images/First.gif" ToolTip="第一页" />
bubuko.com,布布扣                            <asp:ImageButton ID="imgBtnPrev" runat="server" CommandArgument="Prev" CommandName="Page"
bubuko.com,布布扣                                ImageUrl="~/Images/Previous.gif" ToolTip="上一页" />
bubuko.com,布布扣                            <asp:ImageButton ID="imgBtnNext" runat="server" CommandArgument="Next" CommandName="Page"
bubuko.com,布布扣                                ImageUrl="~/Images/Next.gif" ToolTip="下一页" />
bubuko.com,布布扣                            <asp:ImageButton ID="imgBtnLast" runat="server" CommandArgument="Last" CommandName="Page"
bubuko.com,布布扣                                ImageUrl="~/Images/Last.gif" ToolTip="最后页" />
bubuko.com,布布扣                        </td>
bubuko.com,布布扣                        <td align="right" width="25%">
bubuko.com,布布扣                            页数:<asp:Label ID="lblCurrentPage" runat="server"></asp:Label>
bubuko.com,布布扣                        </td>
bubuko.com,布布扣                    </tr>
bubuko.com,布布扣                </table>
bubuko.com,布布扣            </PagerTemplate>

后台绑定事件:

 

bubuko.com,布布扣
bubuko.com,布布扣protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
bubuko.com,布布扣        {
bubuko.com,布布扣            #region 这里主要是换一种分页方式
bubuko.com,布布扣            // 取得显示页数的那一列。
bubuko.com,布布扣            GridViewRow pagerRow = GridView1.BottomPagerRow;
bubuko.com,布布扣            if (pagerRow != null)
bubuko.com,布布扣            {
bubuko.com,布布扣                // 取得显示目前所在页数的 Label 控件。
bubuko.com,布布扣                Label pageLabel = (Label)(pagerRow.Cells[0].FindControl("lblCurrentPage"));
bubuko.com,布布扣
bubuko.com,布布扣                // 取得 第一页、上一页、下一页、最后页 的按钮。
bubuko.com,布布扣                ImageButton imgBtnFirst =
bubuko.com,布布扣                  (ImageButton)(pagerRow.Cells[0].FindControl("imgBtnFirst"));
bubuko.com,布布扣                ImageButton imgBtnPrev =
bubuko.com,布布扣                  (ImageButton)(pagerRow.Cells[0].FindControl("imgBtnPrev"));
bubuko.com,布布扣                ImageButton imgBtnNext =
bubuko.com,布布扣                  (ImageButton)(pagerRow.Cells[0].FindControl("imgBtnNext"));
bubuko.com,布布扣                ImageButton imgBtnLast =
bubuko.com,布布扣                  (ImageButton)(pagerRow.Cells[0].FindControl("imgBtnLast"));
bubuko.com,布布扣
bubuko.com,布布扣                // 设定何时应该显示 第一页、上一页、下一页、最后页 的按钮。
bubuko.com,布布扣                if (GridView1.PageIndex == 0)
bubuko.com,布布扣                {
bubuko.com,布布扣                    imgBtnFirst.Style.Add(HtmlTextWriterStyle.Visibility, "hidden");
bubuko.com,布布扣                    imgBtnPrev.Style.Add(HtmlTextWriterStyle.Visibility, "hidden");
bubuko.com,布布扣                }
bubuko.com,布布扣                else if (GridView1.PageIndex == GridView1.PageCount - 1)
bubuko.com,布布扣                {
bubuko.com,布布扣                    imgBtnLast.Style.Add(HtmlTextWriterStyle.Visibility, "hidden");
bubuko.com,布布扣                    imgBtnNext.Style.Add(HtmlTextWriterStyle.Visibility, "hidden");
bubuko.com,布布扣                }
bubuko.com,布布扣                else if (GridView1.PageCount <= 0)
bubuko.com,布布扣                {
bubuko.com,布布扣                    imgBtnFirst.Style.Add(HtmlTextWriterStyle.Visibility, "hidden");
bubuko.com,布布扣                    imgBtnPrev.Style.Add(HtmlTextWriterStyle.Visibility, "hidden");
bubuko.com,布布扣                    imgBtnNext.Style.Add(HtmlTextWriterStyle.Visibility, "hidden");
bubuko.com,布布扣                    imgBtnLast.Style.Add(HtmlTextWriterStyle.Visibility, "hidden");
bubuko.com,布布扣                }
bubuko.com,布布扣
bubuko.com,布布扣                if (pageLabel != null)
bubuko.com,布布扣                {
bubuko.com,布布扣                    // 计算目前所在的页数。
bubuko.com,布布扣                    int currentPage = GridView1.PageIndex + 1;
bubuko.com,布布扣
bubuko.com,布布扣                    pageLabel.Text = currentPage.ToString() +
bubuko.com,布布扣                        " / " + GridView1.PageCount.ToString();
bubuko.com,布布扣                }
bubuko.com,布布扣            }
bubuko.com,布布扣            #endregion
bubuko.com,布布扣
bubuko.com,布布扣        }


bind_gv()是
DataTable dt = new DataTable();
//dt = ClsDataBase.ExecuteNonQuery("select * from test");//这里放你的查询方法
this.GridView1.DataSource = dt;
this.GridView1.DataBind();

(出处:http://blog.csdn.net/zhaoqiliang527/archive/2009/02/15/3893312.aspx)

GridView分页(第一页、上一页、下一页、最后页、当前页数/总页数)

标签:style   blog   http   io   os   ar   div   art   sp   

原文地址:http://www.cnblogs.com/lschenblog/p/3979942.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!