jeudi 25 juin 2015

How to make next page visible false?

Im new to c# asp.net web form. here's my code for the PagedDataSource for pagination in aspx.cs:

//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();
}

The BindRepeater function is where I get the pagenumber for my data. My question is What condition should I make for my PageNumber to make the next page not visible? When I search Example:Country(Aduanas) the country that I searched only has 2 data in it but the function linkNext_Click() is visible even if there is only 2 data.

Here's an image of it: enter image description here

How do I make my NextPage link not visible in the PageNumber Condition:

What condition should I add to make the nextpage visible false in the image above?

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;
}

Aucun commentaire:

Enregistrer un commentaire