Paging Advantage of Datalist Control in asp.net with c#&visual basic
Server Side Coding: c#
SqlConnection scn = new SqlConnection("Data Source=.;Initial Catalog=iptv_database;Integrated Security=True");
int Start;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ViewState["Start"] = 0;
BindData();
}
}
void BindData()
{
SqlDataAdapter da = new SqlDataAdapter("select * from addprogram", scn);
DataSet ds= new DataSet();
Start = (int)ViewState["Start"];
ViewState["Size"] = 2;
da.Fill(ds,Start,(int)ViewState["Size"], "addprogram");
DataList1.DataSource = ds;
DataList1.DataBind();
}
protected void lnkPrevious_Click(object sender, EventArgs e)
{
Start = (int)ViewState["Start"] - (int)ViewState["Size"];
ViewState["Start"] = Start;
if (Start <= 0)
{
ViewState["Start"] = 0;
}
BindData();
}
protected void lnkNext_Click(object sender, EventArgs e)
{
int count = DataList1.Items.Count;
Start = (int)ViewState["Start"] + (int)ViewState["Size"];
ViewState["Start"] = Start;
if (count <(int)ViewState["Size"])
{
ViewState["Start"] = (int)ViewState["Start"] + (int)ViewState["Size"];
Start = (int)ViewState["Start"];}
}
Category: