using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Common;
using System.Data.SqlClient;
using digioz;

public partial class controls_News : System.Web.UI.UserControl
{
    private void BindData()
    {
        int currentpage = 1;
        if (!(string.IsNullOrEmpty(LabelPageNum1.Text)))
        {
            currentpage = Convert.ToInt32(LabelPageNum1.Text);
        }
        else
        {
            LabelPageNum1.Text = "1";
        }
        PagedDataSource ps = new PagedDataSource();
        ps.DataSource = NewsManagement.GetNewsList();
        ps.AllowPaging = true;
        ps.PageSize = 2;
        ps.CurrentPageIndex = currentpage - 1;
        ButtonFirstPage1.Enabled = true;
        ButtonPrePage1.Enabled = true;
        ButtonNextPage1.Enabled = true;
        ButtonLastPage1.Enabled = true;
        if (currentpage == 1)
        {
            ButtonFirstPage1.Enabled = false;
            ButtonPrePage1.Enabled = false;
        }
        if (currentpage == ps.PageCount)
        {
            ButtonNextPage1.Enabled = false;
            ButtonLastPage1.Enabled = false;
        }
        LabelPageAmount1.Text = Convert.ToString(ps.PageCount);
        dl_articles.DataSource = ps;
        dl_articles.DataBind();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!(Page.IsPostBack))
        {
            BindData();
        }
    }

    protected void ButtonFirstPage1_Click(object sender, EventArgs e)
    {
        LabelPageNum1.Text = "1";
        BindData();
    }

    protected void ButtonPrePage1_Click(object sender, EventArgs e)
    {
        LabelPageNum1.Text = Convert.ToString(Convert.ToInt32(LabelPageNum1.Text) - 1);
        BindData();
    }

    protected void ButtonNextPage1_Click(object sender, EventArgs e)
    {
        LabelPageNum1.Text = Convert.ToString(Convert.ToInt32(LabelPageNum1.Text) + 1);
        BindData();
    }

    protected void ButtonLastPage1_Click(object sender, EventArgs e)
    {
        LabelPageNum1.Text = LabelPageAmount1.Text;
        BindData();
    }
}
