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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.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# ASP.NET“分页下一页”按钮无法正常工作_C#_Asp.net_Pagination_Repeater_Paging - Fatal编程技术网

C# ASP.NET“分页下一页”按钮无法正常工作

C# ASP.NET“分页下一页”按钮无法正常工作,c#,asp.net,pagination,repeater,paging,C#,Asp.net,Pagination,Repeater,Paging,我正试图用一个转发器将我列出的所有产品分成几页。例如,有3页。页面看起来不错,但当我点击“下一页”按钮时,它将进入实际上不存在的第4页。原因可能是什么?执行情况如下 private void showShoes() { dataInThePage = new PagedDataSource() { DataSource = ap.getShoes(), AllowPaging = true,

我正试图用一个转发器将我列出的所有产品分成几页。例如,有3页。页面看起来不错,但当我点击“下一页”按钮时,它将进入实际上不存在的第4页。原因可能是什么?执行情况如下

    private void showShoes() 
    {
        dataInThePage = new PagedDataSource()
        {
            DataSource = ap.getShoes(),
            AllowPaging = true,
            PageSize = 2,
            CurrentPageIndex = pageNo
        };

        shoeRepeater.DataSource = dataInThePage;
        shoeRepeater.DataBind();

        pageAmount = dataInThePage.PageCount - 1;
        //
        pageInfoLabel.Text = "Page: " + (dataInThePage.CurrentPageIndex + 1) + "/" + dataInThePage.PageCount + " - Number of Shoes: " + (dataInThePage.DataSourceCount);
        //
        previousButton.Enabled = !dataInThePage.IsFirstPage;
        nextButton.Enabled = !dataInThePage.IsLastPage;
    }

    private int pageNo
    {
        get
        {
            if (ViewState["pageNumber"] != null)
                return Convert.ToInt32(ViewState["pageNumber"]);
            return 0;
        }
        set
        {
            ViewState["pageNumber"] = value;
        }
    }
    private int pageAmount
    {
        get
        {
            if (ViewState["pageNumber"] != null)
                return Convert.ToInt32(ViewState["pageNumber"]);
            return 0;
        }
        set { ViewState["pageNumber"] = value; }
    }
    public PagedDataSource dataInThePage { get; set; }

    protected void previousButton_Click(object sender, EventArgs e)
    {
        pageNo -= 1;
        showShoes();
    }

    protected void nextButton_Click(object sender, EventArgs e)
    {
            pageNo += 1;
            showShoes();
    }
前端:

                <ajaxToolkit:TabPanel ID="TabPanel5" runat="server">
                <HeaderTemplate>Show Shoes</HeaderTemplate>
                <ContentTemplate runat="server">                                                               
                    <asp:Repeater ID="shoeRepeater" runat="server">
                        <HeaderTemplate></HeaderTemplate>
                        <ItemTemplate>
                            <table border="1" style="border-color:#ff9900; width:400px; font-weight:bold; font-family:'Oswald', Arial, sans-serif;">
                                <tr>
                                    <td rowspan="6" style="width:150px; height:150px;">
                                        <image src="shoeImages/<%#DataBinder.Eval(Container.DataItem,"ImagePath") %>"></image>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <%#DataBinder.Eval(Container.DataItem,"BrandName") %> - <%#DataBinder.Eval(Container.DataItem,"ModelName") %> 
                                    </td>

                                </tr>
                                <tr>
                                    <td>
                                        Price: $<%#DataBinder.Eval(Container.DataItem,"Price") %>
                                    </td>

                                </tr>
                                <tr>
                                    <td>
                                        Size: <%#DataBinder.Eval(Container.DataItem,"Size") %>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Color: <%#DataBinder.Eval(Container.DataItem,"PrimaryColor") %> - <%#DataBinder.Eval(Container.DataItem,"SecondaryColor") %> 
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Quantity: <%#DataBinder.Eval(Container.DataItem,"Quantity") %>
                                    </td>

                                </tr>
                            </table>
                        </ItemTemplate>
                        <FooterTemplate></FooterTemplate>
                    </asp:Repeater>
                    <div style="width:600px; height:20px;">
                        <div style="width:50px; height:100%; float:left">
                            <asp:Button ID="previousButton" runat="server" OnClick="previousButton_Click" Text="<<" Width="50px"/>
                        </div>
                        <div style="width:500px; height:100%; float:left; text-align:center">
                            <asp:Label ID="pageInfoLabel" runat="server" Text=" "></asp:Label>
                        </div>
                        <div style="width:50px; height:100%; float:left">
                            <asp:Button ID="nextButton" runat="server" OnClick="nextButton_Click" Text=">>" Width="50px"/>
                        </div>
                    </div>
                </ContentTemplate>               
            </ajaxToolkit:TabPanel>

展示鞋
-  
价格:$
尺寸:
颜色:-
数量:

我不得不猜测一些事情,但是我能够使用ASP.NET 4.0项目将发布的代码应用到VS 2010中

以下是我为让它工作所做的事情:

  • 添加带有.aspx页面中引用的8个公共属性的
    Shoe
    POCO(未显示)
  • 添加一个
    FakeShoeRepository
    类,该类具有带有9个鞋的
    私有静态列表
    (未显示)
  • 添加一个名为
    getShoes()
    的静态方法,该方法返回对存储库私有成员变量的引用(未显示)
  • 设置
    dataInThePage.DataSource=fakeshoepository.getShoes()
    (未显示)
  • 添加
    页面加载()
    事件

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            pageNo = 0;
            showShoes();
        }
    }
    
  • 删除
    pageAmount
    属性

  • 删除在
    showShoes()
    方法中设置的一个位置
    pageAmount
    (这有效地设置了
    ViewState[“pageNumber”]=PageCount-1

最后两项是所提供代码中实际存在的问题。

为什么要提供前5项条件?我无法理解主要观点,因为正如你所说,最后2个已经足够了。我添加这些内容是因为我想记录我对你的问题所做的假设。他们对我来说是必要的,以产生一个工作的例子,并找到问题。