Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何手动设置ListView项目总数_C#_Asp.net_Listview - Fatal编程技术网

C# 如何手动设置ListView项目总数

C# 如何手动设置ListView项目总数,c#,asp.net,listview,C#,Asp.net,Listview,我想在我的asp.net页面中实现分页功能。所以我制作了ListView和DatePager <div class="pagination"> <div class="numeric"> <asp:DataPager ID="resultListPager" runat="server" PagedControlID="resultList"

我想在我的asp.net页面中实现分页功能。所以我制作了ListView和DatePager

<div class="pagination">
                    <div class="numeric">
                    <asp:DataPager ID="resultListPager" runat="server"
                       PagedControlID="resultList">
                       <Fields>
                          <asp:NextPreviousPagerField ButtonType="Link" ShowNextPageButton="False" PreviousPageText="< Prev" />
                          <asp:NumericPagerField ButtonType="Link" NumericButtonCssClass="numericLink" />
                          <asp:NextPreviousPagerField ButtonType="Link" ShowPreviousPageButton="false" ShowNextPageButton="False" ShowLastPageButton="True" />
                          <asp:NextPreviousPagerField ButtonType="Link" ShowPreviousPageButton="false" NextPageText="Next >" />
                       </Fields>
                    </asp:DataPager>
                    </div>
                </div>

                <asp:ListView ID="resultList" runat="server" ItemPlaceholderID="itemPlaceholder" OnPagePropertiesChanging="ChangePage">

                <LayoutTemplate>
                <ul class="items_list5">
                    <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
                </ul>
                </LayoutTemplate>

                <ItemTemplate>
                <li class="cat_item">
                <div class="item_image">
                                <a href="#"><img src="<%#Eval("Image")%>" alt="" /></a>
                            </div>
                            <div class="item_description">
                                <%#Eval("Name")%>
                            </div>
                </li>
                </ItemTemplate>

                <EmptyDataTemplate>
                <div>Sorry - no items found.</div>
                </EmptyDataTemplate>
                </asp:ListView>


抱歉-找不到任何项目。
问题是,由于我只从数据库中获取前10个元素,所以分页只显示一个页面

int totalCount;
List<GiftVoucher> vouchers = GiftVoucher.Search(querystring, pageNumber, count, out totalCount);
resultList.DataSource = vouchers;
resultList.DataBind();
inttotalcount;
列表凭证=GiftVoucher.Search(查询字符串、页码、计数、out totalCount);
resultList.DataSource=凭证;
resultList.DataBind();
例如,如果我的totalCount是50,我想让我的分页有5页。。。现在它只显示一个页面,因为我只从数据库中获取前10条记录


那么,如何手动将listview的total items counts设置为my totalCount变量?

切换到ObjectDataSource并设置SelectMethod和SelectCountMethod。这样列表不仅可以获得当前页面,还可以获得项目总数