gridview首頁、上一頁、下一頁、末頁

在.aspx頁面拉四個Button:   

                              <asp:Button ID="btnfirst" runat="server" οnclick="button_click" Text="首  頁"
                                    CommandArgument="first" />
                                <asp:Button ID="btnup" runat="server" οnclick="button_click" Text="上一頁"
                                    CommandArgument="up" />
                                <asp:Button ID="btnnext" runat="server" οnclick="button_click" Text="下一頁"
                                    CommandArgument="next" />
                                <asp:Button ID="btnlast" runat="server" οnclick="button_click" Text="末  頁"
                                    CommandArgument="last" />

 

在.aspx.cs頁面添加代碼:

        protected void button_click(object sender, EventArgs e)
        {
            string commandString = ((Button)sender).CommandArgument.ToString();
            switch (commandString)
            {
                case "next":
                    if(this.GridView1.PageIndex<(GridView1.PageCount-1))
                    {
                        GridView1.PageIndex +=1;
                    }
                    break;
                case "up":
                    if(this.GridView1.PageIndex>0)
                    {
                        GridView1.PageIndex-=1;
                    }
                    break;
                case"last":
                    this.GridView1.PageIndex=(GridView1.PageCount-1);
                    break;
                case"first":
                    this.GridView1.PageIndex=0;
                    break;
            }
        }

發佈了27 篇原創文章 · 獲贊 4 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章