我是c#asp.net网络表单的新手。这是我在aspx.cs中用于分页的PagedDataSource的代码:
//This property will contain the current page number
public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
{
return Convert.ToInt32(ViewState["PageNumber"]);
}
else
{
return 0;
}
}
set { ViewState["PageNumber"] = value; }
}
//Asp:ListView
private void BindRepeater()
{
//ConnectionString for accessing into MSSql
connector.ConnectionString = "SERVER=xbetasql,52292;UID=AutoTrakker;Password=trinidad2win;DATABASE=ATDBSQL;";
//Get the values from id's
string customer = (this.search.Value);
string country = (this.Country.Value);
string idcurrency = (this.Currency.Value);
//Conditions for query
if (country != "select")
{
if (idcurrency != "selected")
{
query = "select * from customer where country = '" + country + "' and idcurrency = '" + idcurrency + "'";
}
else
{
query = "select * from customer where country = '" + country + "'";
}
}
else if (idcurrency != "selected")
{
query = "select * from customer where idcurrency = '" + idcurrency + "'";
}
else if ((this.search.Value) == customer)
{
query = "select * from customer where idcustomer = '" + customer + "'";
}
else if (customer == "")
{
Response.Write("<script>alert('No Id Inputted, Data Not Found.')</script>");
}
//DataSet and DataTable (get the data and display it into asp:repeater
selectedData = connector.ExecuteQuery(query);
dt = selectedData.Tables[0];
//Set PageData Settings
PagedDataSource pagedData = new PagedDataSource();
pagedData.DataSource = dt.DefaultView;
pagedData.AllowPaging = true;
pagedData.PageSize = 2;
pagedData.CurrentPageIndex = PageNumber;
int vcnt = dt.DefaultView.Count / pagedData.PageSize;
if (PageNumber == 1)
{
linkPrevious.Visible = false;
linkNext.Visible = false;
}
else if (PageNumber < 1)
{
linkPrevious.Visible = false;
linkNext.Visible = false;
}
else if (PageNumber > 0)
{
linkPrevious.Visible = true;
}
if (PageNumber >= vcnt)
{
linkNext.Visible = false;
}
else if(PageNumber < vcnt)
{
linkNext.Visible = true;
linkPrevious.Visible = !pagedData.IsFirstPage;
}
//Binding the repeater
if (dt.Rows.Count > 0)
{
repeater.Visible = true;
repeater.DataSource = pagedData;
repeater.DataBind();
}
else
{
Response.Write("<script>alert('No Data Found.')</script>");
}
}
protected void linkNext_Click(object sender, EventArgs e)
{
linkNext.Visible = true;
PageNumber += 1;
BindRepeater();
}
protected void linkPrevious_Click(object sender, EventArgs e)
{
linkPrevious.Visible = true;
PageNumber -= 1;
BindRepeater();
}
BindRepeater函数是我获取数据的pagenumber的地方。我的问题是我应该为我的PageNumber做什么条件才能使下一页不可见?当我搜索示例:Country(Aduanas)时,我搜索的国家/地区只有2个数据,但函数linkNext_Click即使只有2个数据,()也可见。
以下是它的图像:
如何在PageNumber条件中看不到NextPage链接:
我应该添加什么条件才能使上一页中的nextpage显示为false?
if (PageNumber == 1)
{
linkPrevious.Visible = false;
linkNext.Visible = false;
}
else if (PageNumber < 1)
{
linkPrevious.Visible = false;
linkNext.Visible = false;
}
else if (PageNumber > 0)
{
linkPrevious.Visible = true;
}
if (PageNumber >= vcnt)
{
linkNext.Visible = false;
}
else if(PageNumber < vcnt)
{
linkNext.Visible = true;
linkPrevious.Visible = !pagedData.IsFirstPage;
}
答案 0 :(得分:0)
知道了!在这种情况下:
else if(PageNumber < vcnt)
{
//linkNext.Visible = true;
// Change it to
linkNext.Visible = !pagedData.IsLastPage;
linkPrevious.Visible = !pagedData.IsFirstPage;
}