SIGN UP MEMBER LOGIN:    
ARTICLE

Datalist with Paging in C#

Posted by sameer das Articles | C# Language December 08, 2010
In this article you will learn how to use Datalist with Paging in C#.
Reader Level:
Download Files:
 

SCRREN SHORT

s.gif

CODE

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;

public partial class gallry : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {          
            fillgrid();
            fil();

        }
    }

    protected void fillgrid()
    {
   
        DataTable dt = dataaccess.Returndata("select *  from apkisakhi_category where status='1' order by category asc"
;         
 
        ddlcategory.DataSource = dt;
        ddlcategory.DataTextField = dt.Columns["category"].ToString();
        ddlcategory.DataValueField = dt.Columns["cat_code"].ToString();
        ddlcategory.DataBind();
     
    }
    protected void ddlcategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            DataTable dt = dataaccess.Returndata("select * from apkisakhi_category where category='" +
ddlcategory.SelectedItem.Text + "'");
         
            if (dt.Rows.Count != 0)
            {
                DataList1.Visible = true;
                DataTable dt1 = dataaccess.Returndata("select * from apkisakhi_meta where cat_code='" +
ddlcategory.SelectedValue.ToString() + "'");
                if (dt1.Rows.Count > 0)
                {
                    Session["title"] = dt1.Rows[0]["title"].ToString();
                    ss.InnerText = Session["title"].ToString();
                }
                fil();
 
            }
            else
            {
                Response.Write("<script>alert('choose one category')</script>");
                DataList1.Visible = false;

                lblcat.Text = "";
            }
        }
        catch (Exception)
        {
            Response.Write("<script>alert('Error')</script>");
        }
       
    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
      
 
    }
    public int currentpage
    {
        get
        {
            object o=this.ViewState["_c"];
            if(o==null)
                return 0;
            else
                return(int)o;
        }
        set
        {
            this.ViewState["_c"]=value;
        }
    }
    private void fil()
    {

        DataTable dt1 = dataaccess.Returndata("select * from apkisakhi_category where category='" + ddlcategory.SelectedItem.Text + "'");
        Session["cat"] = dt1.Rows[0]["cat_code"].ToString();
        lblcat.Text = dt1.Rows[0]["category"].ToString();
        DataTable dt = dataaccess.Returndata("select * from apkisakhi_addjellewery where status='1' and cat_code='" + Session["cat"] + "'  order by j_code asc   ");
        PagedDataSource p = new PagedDataSource();
        p.DataSource = dt.DefaultView;
        p.AllowPaging = true;
        p.PageSize = 15;
        p.CurrentPageIndex = currentpage;
        lblpage.Text="Page: "+" "+(currentpage+1).ToString()+" "+" of "+p.PageCount.ToString();
        prev.Enabled = !p.IsFirstPage;
        next.Enabled = !p.IsLastPage;
        DataList1.DataSource = p;
        DataList1.DataBind();
    }

    protected void prev_Click(object sender, EventArgs e)
    {
        currentpage -= 1;
        fil();
    }
    protected void next_Click(object sender, EventArgs e)
    {
        currentpage += 1;
        fil();
 
    }
}

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
Become a Sponsor