佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > .net GridView分頁模板的實(shí)例代碼

.net GridView分頁模板的實(shí)例代碼

熱門標(biāo)簽:服務(wù)器配置 阿里云 科大訊飛語音識別系統(tǒng) 團(tuán)購網(wǎng)站 電子圍欄 銀行業(yè)務(wù) Linux服務(wù)器 Mysql連接數(shù)設(shè)置

復(fù)制代碼 代碼如下:

//要在GridView中加入如下屬性(前臺還是后臺看你的習(xí)慣了。)

//實(shí)現(xiàn)分頁

AllowPaging="true"

//一頁數(shù)據(jù)10行

 PageSize="10"

// 分頁時(shí)觸發(fā)的事件
OnPageIndexChanging="gvwDesignationName_PageIndexChanging"

//在服務(wù)器事件里

protected void gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvwDesignationName.PageIndex=e.newIndex;

bingDesignatioonName();
}


//這里我給出一個(gè)通用顯示分頁的模板

PagerTemplate>
                當(dāng)前第:
                //((GridView)Container.NamingContainer)就是為了得到當(dāng)前的控件
                asp:Label ID="LabelCurrentPage" runat="server" Text="%# ((GridView)Container.NamingContainer).PageIndex + 1 %>">/asp:Label>
                頁/共:
                //得到分頁頁面的總數(shù)
                asp:Label ID="LabelPageCount" runat="server" Text="%# ((GridView)Container.NamingContainer).PageCount %>">/asp:Label>
                頁
                 //如果該分頁是首分頁,那么該連接就不會顯示了.同時(shí)對應(yīng)了自帶識別的命令參數(shù)CommandArgument
                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>
                轉(zhuǎn)到第
                asp:TextBox ID="txtNewPageIndex" runat="server" Width="20px" Text='%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />頁
                //這里將CommandArgument即使點(diǎn)擊該按鈕e.newIndex 值為3
                asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-2"
                    CommandName="Page" Text="GO" />
            /PagerTemplate>

//對應(yīng)該事件中代碼為


 protected void gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 得到該控件
        GridView theGrid = sender as GridView;
        int newPageIndex = 0;
        if (e.NewPageIndex==-3)
        {
            //點(diǎn)擊了Go按鈕
            TextBox txtNewPageIndex = null;

            //GridView較DataGrid提供了更多的API,獲取分頁塊可以使用BottomPagerRow 或者TopPagerRow,當(dāng)然還增加了HeaderRow和FooterRow
            GridViewRow pagerRow = theGrid.BottomPagerRow;

            if (pagerRow != null)
            {
                //得到text控件
                txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;   
            }
            if ( txtNewPageIndex!= null)
            {
                //得到索引
                newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
            }
        }
        else
        {
            //點(diǎn)擊了其他的按鈕
            newPageIndex = e.NewPageIndex;
        }
        //防止新索引溢出
        newPageIndex = newPageIndex 0 ? 0 : newPageIndex;
        newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;

        //得到新的值
        theGrid.PageIndex = newPageIndex;

         //重新綁定
        bingDesignatioonName();
    }

您可能感興趣的文章:
  • Asp.net GridView使用大全(分頁實(shí)現(xiàn))
  • GridView分頁的實(shí)現(xiàn)(通用分頁模板)
  • AspNetPager+GridView實(shí)現(xiàn)分頁的實(shí)例代碼
  • GridView高效分頁和搜索功能的實(shí)現(xiàn)代碼
  • GridView自定義分頁的四種存儲過程
  • GridView分頁的實(shí)現(xiàn)以及自定義分頁樣式功能實(shí)例

標(biāo)簽:棗莊 萍鄉(xiāng) 衡水 廣元 江蘇 大理 蚌埠 衢州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《.net GridView分頁模板的實(shí)例代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    汕头市| 凯里市| 孟连| 赣榆县| 石城县| 桐柏县| 临泉县| 内黄县| 内乡县| 吉隆县| 化州市| 尼木县| 龙南县| 清新县| 长丰县| 金塔县| 德化县| 红原县| 娄烦县| 云浮市| 屯门区| 察哈| 德化县| 新乡市| 沁阳市| 高安市| 龙川县| 盐津县| 会宁县| 峨边| 富宁县| 正安县| 张家界市| 中方县| 柯坪县| 陆川县| 古丈县| 商洛市| 怀仁县| 五河县| 昌江|