<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        如何實現ListView高效分頁代碼

        來源:懂視網 責編:小采 時間:2020-11-27 22:41:44
        文檔

        如何實現ListView高效分頁代碼

        如何實現ListView高效分頁代碼:ListView選擇自動分頁時 其實就是添加了一個DataPager分頁控件兩者間存在著嵌套關系《Repeater與ListView》中提到這樣的分頁并不是高效的 因為數據源還是返回了所有的數據 而非當前頁數據 優化方案及步驟: 1.改數據源EnablePaging屬性為tru
        推薦度:
        導讀如何實現ListView高效分頁代碼:ListView選擇自動分頁時 其實就是添加了一個DataPager分頁控件兩者間存在著嵌套關系《Repeater與ListView》中提到這樣的分頁并不是高效的 因為數據源還是返回了所有的數據 而非當前頁數據 優化方案及步驟: 1.改數據源EnablePaging屬性為tru

        ListView選擇自動分頁時  其實就是添加了一個DataPager分頁控件兩者間存在著嵌套關系《Repeater與ListView》中提到這樣的分頁并不是高效的 因為數據源還是返回了所有的數據  而非當前頁數據 

        優化方案及步驟:

        1.改數據源EnablePaging屬性為true 【允許分頁】

        設置MaximumRowsParameterName="rowIndex"【MSDN解釋:該參數接受檢索的行數的值  可以理解為:上一頁的最后一行的下標】

        設置StartRowIndexParameterName="pageSize"【MSDN解釋:該參數接受要檢索的第一行索引的值  可以理解為pageSize 即每頁顯示條數】

        SelectCountMethod="GetTotalRowsCount" 【需要總行數數時執行的方法即一共有多少條數據告訴分頁控件如何顯示】

        2、此時數據源調用的原有方法getAllClasses不再滿足要求需要在業務層中新增一個帶MaximumRowsParameterName及StartRowIndexParameterName參數名稱的方法  以及GetTotalRowsCount兩個方法

        BLL層添加如下:

        代碼如下:
        View Code

        public List <MODEL.Classes > getPageListByPage( int pageSize, int rowIndex) {            return dal.getPageListByPage(pageSize, rowIndex, false);
                }

                public int GetTotalRowsCount() {
                    return dal.GetTotalRowsCount();
                }

        DAL層添加如下:

        代碼如下:
        View Code

        public List <MODEL. Classes> getPageListByPage( int rowIndex, int pageSize, bool isDel) {            int rowCount = 0;
                    int pageCount = 0;
                    DataTable dt = SqlHelper .getPageListByPage(rowIndex, pageSize, out rowCount, out pageCount, isDel);
                    if (dt.Rows.Count > 0) {
                        List <MODEL.Classes > list = new List <MODEL.Classes >();
                        foreach (DataRow dr in dt.Rows) {
                            MODEL. Classes model = new MODEL. Classes();
                            LoadEntityData(model, dr);
                            list.Add(model);
                        }
                        return list;
                    }
                    return null ;
                }

                public int GetTotalRowsCount() {
                    string sqlstr = "select * from classes where cisdel = 0" ;
                    return SqlHelper .ExecuteScalar(sqlstr);
                }

        SqlHelper新增方法如下:

        代碼如下:
        View Code

        public static DataTable getPageListByPage( int rowIndex, int pageSize, out int rowCount, out int pageCount, bool isDel) {            DataTable dtcalss = new DataTable();
                    rowCount = 0;
                    pageCount = 0;
                    using (SqlConnection sqlcon = new SqlConnection (Connstr)) {
                        SqlDataAdapter sda = new SqlDataAdapter( "up_GetPageData2" , sqlcon);
                        SqlParameter [] pars = {
                                              new SqlParameter ( "@LastRowIndex",rowIndex),
                                              new SqlParameter ( "@pgSize",pageSize),
                                                new SqlParameter ( "@rowCount",rowCount),
                                                new SqlParameter ( "@pgCount",pageCount),
                                                new SqlParameter ( "@isDel",isDel),
                                              };
                        //將兩個輸出參數的輸出方向指定
                        pars[2].Direction = ParameterDirection .Output;
                        pars[3].Direction = ParameterDirection .Output;
                        //將參數集合 加入到 查詢命令對象中
                        sda.SelectCommand.Parameters.AddRange(pars);
                        //設置 查詢命令類型 為存儲過程
                        sda.SelectCommand.CommandType = CommandType .StoredProcedure;
                        //執行存儲過程
                        sda.Fill(dtcalss);
                        //執行完后 將存儲過程 獲得的 兩個輸出參數值 賦給此方法的兩個輸出參數
                        rowCount = Convert .ToInt32(pars[2].Value);
                        pageCount = Convert .ToInt32(pars[3].Value);
                    }
                    return dtcalss;
                }

        存儲過程up_GetPageData2代碼如下:

        代碼如下:
        View Code

        create proc up_GetPageData2
        @LastRowIndex int , ---上一頁的最后一行的下標
        @pgSize float , --頁容量
        @rowCount int output, --- 輸出總行數
        @pgCount int output, --- 輸出 總頁數
        @isDel   bit --數據是否刪除
        as
        begin
              select @rowCount =count (*) from classes where cisdel= @isDel --查出總行數
              set @pgCount =ceiling ( @rowCount/ @pgSize )-- 算出總頁數
              select * from (
                  select Row_Number () over ( order by cid ) as RNum, * from classes where cisdel= @isDel
              ) as temp
              where RNum >@LastRowIndex and RNum <= @LastRowIndex +@pgSize
        end

        ListView.aspx代碼如下:

        代碼如下:
        View Code

        <% @ Page Language="C#" AutoEventWireup="true" CodeBehind="ListView.aspx.cs" Inherits ="WebForm.ListView" %>
        <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        < html xmlns ="http://www.w3.org/1999/xhtml">
        < head runat ="server">
            <title ></ title>
        </ head>
        < body>
            <form id="form1" runat="server">
            <div >

                < asp: ObjectDataSource ID ="ObjectDataSource1" runat ="server"
                    SelectMethod ="getPageListByPage" TypeName ="BLL.Classes"
                    DataObjectTypeName ="MODEL.Classes" DeleteMethod ="SoftDel" InsertMethod ="Add"
                    UpdateMethod ="Modify" EnablePaging ="True"
                    MaximumRowsParameterName ="rowIndex" SelectCountMethod ="GetTotalRowsCount"
                    StartRowIndexParameterName ="pageSize">
                </ asp: ObjectDataSource >
                < asp: ListView ID ="ListView1" runat ="server" DataSourceID ="ObjectDataSource1"
                    InsertItemPosition ="LastItem">
                    < AlternatingItemTemplate>
                        < tr style ="">
                            < td>
                                < asp: Button ID ="DeleteButton" runat ="server" CommandName ="Delete" Text ="刪除" />
                                < asp: Button ID ="EditButton" runat ="server" CommandName ="Edit" Text ="編輯" />
                            </ td>
                            < td>
                                < asp: Label ID ="CIDLabel" runat ="server" Text =' <%# Eval("CID") %> ' />
                            </ td>
                            < td>
                                < asp: Label ID ="CNameLabel" runat ="server" Text =' <%# Eval("CName") %> ' />
                            </ td>
                            < td>
                                < asp: Label ID ="CCountLabel" runat ="server" Text =' <%# Eval("CCount") %> ' />
                            </ td>
                            < td>
                                < asp: Label ID ="CImgLabel" runat ="server" Text =' <%# Eval("CImg") %> ' />
                            </ td>
                            < td>
                                < asp: CheckBox ID ="CIsDelCheckBox" runat ="server"
                                    Checked ='<% # Eval("CIsDel") %> ' Enabled ="false" />
                            </ td>
                            < td>
                                < asp: Label ID ="CAddTimeLabel" runat ="server" Text =' <%# Eval("CAddTime") %> ' />
                            </ td>
                        </ tr>
                    </ AlternatingItemTemplate>

                    < EditItemTemplate>
                        < tr style ="">
                            < td>
                                < asp: Button ID ="UpdateButton" runat ="server" CommandName ="Update" Text ="更新" />
                                < asp: Button ID ="CancelButton" runat ="server" CommandName ="Cancel" Text ="取消" />
                            </ td>
                            < td>
                                < asp: TextBox ID ="CIDTextBox" runat ="server" Text =' <%# Bind("CID") %> ' />
                            </ td>
                            < td>
                                < asp: TextBox ID ="CNameTextBox" runat ="server" Text =' <%# Bind("CName") %> ' />
                            </ td>
                            < td>
                                < asp: TextBox ID ="CCountTextBox" runat ="server" Text =' <%# Bind("CCount") %> ' />
                            </ td>
                            < td>
                                < asp: TextBox ID ="CImgTextBox" runat ="server" Text =' <%# Bind("CImg") %> ' />
                            </ td>
                            < td>
                                < asp: CheckBox ID ="CIsDelCheckBox" runat ="server"
                                    Checked ='<% # Bind("CIsDel") %> ' />
                            </ td>
                            < td>
                                < asp: TextBox ID ="CAddTimeTextBox" runat ="server"
                                    Text ='<% # Bind("CAddTime") %> ' />
                            </ td>
                        </ tr>
                    </ EditItemTemplate>
                    < EmptyDataTemplate>
                        < table runat ="server"

                            style ="">
                            < tr>
                                < td>
                                    未返回數據。 </ td>
                            </ tr>
                        </ table>
                    </ EmptyDataTemplate>
                    < InsertItemTemplate>
                        < tr style ="">
                            < td>
                                < asp: Button ID ="InsertButton" runat ="server" CommandName ="Insert" Text ="插入" />
                                < asp: Button ID ="CancelButton" runat ="server" CommandName ="Cancel" Text ="清除" />
                            </ td>
                            < td>
                                < asp: TextBox ID ="CIDTextBox" runat ="server" Text =' <%# Bind("CID") %> ' />
                            </ td>
                            < td>
                                < asp: TextBox ID ="CNameTextBox" runat ="server" Text =' <%# Bind("CName") %> ' />
                            </ td>
                            < td>
                                < asp: TextBox ID ="CCountTextBox" runat ="server" Text =' <%# Bind("CCount") %> ' />
                            </ td>
                            < td>
                                < asp: TextBox ID ="CImgTextBox" runat ="server" Text =' <%# Bind("CImg") %> ' />
                            </ td>
                            < td>
                                < asp: CheckBox ID ="CIsDelCheckBox" runat ="server"
                                    Checked ='<% # Bind("CIsDel") %> ' />
                            </ td>
                            < td>
                                < asp: TextBox ID ="CAddTimeTextBox" runat ="server"
                                    Text ='<% # Bind("CAddTime") %> ' />
                            </ td>
                        </ tr>
                    </ InsertItemTemplate>
                    < ItemTemplate>
                        < tr style ="">
                            < td>
                                < asp: Button ID ="DeleteButton" runat ="server" CommandName ="Delete" Text ="刪除" />
                                < asp: Button ID ="EditButton" runat ="server" CommandName ="Edit" Text ="編輯" />
                            </ td>
                            < td>
                                < asp: Label ID ="CIDLabel" runat ="server" Text =' <%# Eval("CID") %> ' />
                            </ td>
                            < td>
                                < asp: Label ID ="CNameLabel" runat ="server" Text =' <%# Eval("CName") %> ' />
                            </ td>
                            < td>
                                < asp: Label ID ="CCountLabel" runat ="server" Text =' <%# Eval("CCount") %> ' />
                            </ td>
                            < td>
                                < asp: Label ID ="CImgLabel" runat ="server" Text =' <%# Eval("CImg") %> ' />
                            </ td>
                            < td>
                                < asp: CheckBox ID ="CIsDelCheckBox" runat ="server"
                                    Checked ='<% # Eval("CIsDel") %> ' Enabled ="false" />
                            </ td>
                            < td>
                                < asp: Label ID ="CAddTimeLabel" runat ="server" Text =' <%# Eval("CAddTime") %> ' />
                            </ td>
                        </ tr>
                    </ ItemTemplate>
                    < LayoutTemplate>
                        < table runat ="server">
                            < tr runat ="server">
                                < td runat ="server">
                                    < table ID ="itemPlaceholderContainer" runat ="server" border ="0"

                                        style ="">
                                        < tr runat ="server" style ="">
                                            < th runat ="server">
                                                </ th>
                                            < th runat ="server">
                                                CID </ th>
                                            < th runat ="server">
                                                CName </ th>
                                            < th runat ="server">
                                                CCount </ th>
                                            < th runat ="server">
                                                CImg </ th>
                                            < th runat ="server">
                                                CIsDel </ th>
                                            < th runat ="server">
                                                CAddTime </ th>
                                        </ tr>
                                        < tr ID ="itemPlaceholder" runat ="server">
                                        </ tr>
                                    </ table>
                                </ td>
                            </ tr>
                            < tr runat ="server">
                                < td runat ="server"

                                    style ="">
                                </ td>
                            </ tr>
                        </ table>
                    </ LayoutTemplate>
                    < SelectedItemTemplate>
                        < tr style ="">
                            < td>
                                < asp: Button ID ="DeleteButton" runat ="server" CommandName ="Delete" Text ="刪除" />
                                < asp: Button ID ="EditButton" runat ="server" CommandName ="Edit" Text ="編輯" />
                            </ td>
                            < td>
                                < asp: Label ID ="CIDLabel" runat ="server" Text =' <%# Eval("CID") %> ' />
                            </ td>
                            < td>
                                < asp: Label ID ="CNameLabel" runat ="server" Text =' <%# Eval("CName") %> ' />
                            </ td>
                            < td>
                                < asp: Label ID ="CCountLabel" runat ="server" Text =' <%# Eval("CCount") %> ' />
                            </ td>
                            < td>
                                < asp: Label ID ="CImgLabel" runat ="server" Text =' <%# Eval("CImg") %> ' />
                            </ td>
                            < td>
                                < asp: CheckBox ID ="CIsDelCheckBox" runat ="server"
                                    Checked ='<% # Eval("CIsDel") %> ' Enabled ="false" />
                            </ td>
                            < td>
                                < asp: Label ID ="CAddTimeLabel" runat ="server" Text =' <%# Eval("CAddTime") %> ' />
                            </ td>
                        </ tr>
                    </ SelectedItemTemplate>
                </ asp: ListView >

            </div >
            <asp : DataPager ID ="DataPager1" runat ="server" PagedControlID ="ListView1"
                PageSize ="5">
                < Fields>
                    < asp: NextPreviousPagerField ButtonType ="Button" ShowFirstPageButton ="True"
                        ShowLastPageButton ="True" />
                </ Fields>
            </asp : DataPager>
            </form >
        </ body>
        </ html>

        3、界面中ListView1取消"開啟分頁"自動分頁  拖入分頁控件DataPage并設置PagedControlID="ListView1"使其與ListView1建立關聯

        4、修改數據源調用的方法為getPageListByPage運行結果如下:

        補充:

        如果運行報錯'ObjectDataSource“ObjectDataSource1”未能找到帶參數的非泛型方法“getPageListByPage”: pageSize, pageIndex。'

        只需刪除aspx界面中

         <SelectParameters>

                        <asp:Parameter DefaultValue="5" Name="pageSize" Type="Int32" />

                        <asp:Parameter Name="rowIndex" Type="Int32" />

        </SelectParameters>

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        如何實現ListView高效分頁代碼

        如何實現ListView高效分頁代碼:ListView選擇自動分頁時 其實就是添加了一個DataPager分頁控件兩者間存在著嵌套關系《Repeater與ListView》中提到這樣的分頁并不是高效的 因為數據源還是返回了所有的數據 而非當前頁數據 優化方案及步驟: 1.改數據源EnablePaging屬性為tru
        推薦度:
        標簽: 實現 代碼 高效
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 一级黄色免费大片| 中文字幕免费视频一| 无忧传媒视频免费观看入口| 国产日韩精品无码区免费专区国产| 一级特黄aa毛片免费观看| 国产区卡一卡二卡三乱码免费| 亚洲国产天堂在线观看| 亚洲成a∧人片在线观看无码| 在线看片免费人成视频福利| 国产乱子影视频上线免费观看| 亚洲狠狠色丁香婷婷综合| 免费看香港一级毛片| 久久亚洲精品成人无码网站| 亚洲av永久中文无码精品| 最新中文字幕免费视频| 99亚洲精品高清一二区| a一级毛片免费高清在线| 啦啦啦www免费视频| 亚洲自偷自偷精品| 在线视频精品免费| 亚洲五月激情综合图片区| 最近中文字幕大全免费视频| 99热亚洲色精品国产88| 亚洲日本在线免费观看| 亚洲国产精品无码一线岛国| 免费人成大片在线观看播放| 自拍偷自拍亚洲精品情侣| 免费一级特黄特色大片| 久久久久亚洲AV无码专区网站| 特级毛片全部免费播放a一级| 啦啦啦手机完整免费高清观看| 黄色毛片免费观看| 久久亚洲国产精品一区二区| 成人免费大片免费观看网站| 亚洲成a人无码亚洲成av无码| 中文字幕亚洲第一| 青青青国产在线观看免费网站| 亚洲美女aⅴ久久久91| 毛片基地免费观看| 亚洲精品无码成人| 日韩人妻无码免费视频一区二区三区 |