中继器寻呼

时间:2011-02-21 23:59:37

标签: c# asp.net

我使用以下代码在转发器内进行分页。我将分页大小设置为3.如果恰好有3个语音气泡 - 显示下一个按钮,当我选择时,我被重定向到空白页面。但是,如果有4个sepeech气泡,一切都很好。有没有办法确保如果页面大小为3 - 没有显示按钮?谢谢!

    PagedDataSource pagedData = new PagedDataSource();
    pagedData.DataSource = ds.Tables[0].DefaultView;
    pagedData.AllowPaging = true;
    pagedData.PageSize = 3;
    pagedData.CurrentPageIndex = pageNum;

    Repeater1.DataSource = pagedData;
    Repeater1.DataBind();

    cmd.Connection.Close();
    cmd.Connection.Dispose();

    if (pageNum == 0)
    {

        btnPrev.Visible = false;

    }
    if (pageNum >= Math.Floor((decimal)ds.Tables[0].Rows.Count / 3))
    {

        btnNext.Visible = false;
    }

}

protected void btnNext_Click(object sender, EventArgs e)
{
    // Redirects to next page
    Response.Redirect("negativestorydetail.aspx?guid=" + id + "&name=" + name + "&role=" + company_role + "&member=" + mem_id + "&company=" + co_id + "&project=" + proj_name + "&proj_id=" + proj_id + "&tag=" + tag + "&page=" + Convert.ToString(pageNum + 1));
}
protected void btnPrev_Click(object sender, EventArgs e)
{
    // Redirects to previous page
    Response.Redirect("negativestorydetail.aspx?guid=" + id + "&name=" + name + "&role=" + company_role + "&member=" + mem_id + "&company=" + co_id + "&project=" + proj_name + "&proj_id=" + proj_id + "&tag=" + tag + "&page=" + Convert.ToString(pageNum - 1));
}

1 个答案:

答案 0 :(得分:3)

这种情况不太有效:

if (pageNum >= Math.Floor((decimal)ds.Tables[0].Rows.Count / 3))
{
    btnNext.Visible = false;
}

在3个结果(或一般N x页面大小结果)的情况下,它无法正常工作。相反它应该是:

if (pageNum >=  Math.Ceiling((decimal)(ds.Tables[0].Rows.Count / 3)) -1)
{
    btnNext.Visible = false;
}

(-1表示您的页码从零开始而不是一个)