Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Visual-Studio , +
Hi,
 
I am using datalist to display some items in asp.net using c#. Is there any method to implement paging in datalist?
 
Thanks...
Posted 30-Sep-11 23:04pm
Comments
infosoftsaranya at 16-Mar-12 7:25am
   
drwerwer
rk_prabakar at 9-Nov-13 6:40am
   
Testing in Code project ;-)
infosoftsaranya at 16-Mar-12 7:25am
   
rtertetrtet
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

A quick Google search gave me these links:
Paging of Data list[^]
DataList Custom Paging in ASP.NET using C#[^]
 
Have a look at them and see if they help.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

namespace PagininDataLista
{
    public partial class Display_question : System.Web.UI.Page
    {
        string ansid;
        string querystr;
        SqlDataAdapter dadapter;
        DataSet dset;
        PagedDataSource adsource;
        string connstring = "Data Source = USER-PC\\SQLEXPRESS; Initial Catalog = medicalvoyager; Integrated Security = true";
        int pos;
        SqlConnection con = new SqlConnection("Data Source = USER-PC\\SQLEXPRESS; Initial Catalog = medicalvoyager; Integrated Security = true");
        protected void Page_Load(object sender, EventArgs e)
        {
            querystr = Request.QueryString["Question"];
            call1();
            if (!IsPostBack)
            {
                ViewState["vs"] = pos;
            }
           pos = (int)this.ViewState["vs"];
            databind();
           
 
        }
        public void databind()
        {
            try
            {
                if (querystr.ToString() == "")
                {
                    Response.Redirect("Forum.aspx");
                }
                else
                {
                    dadapter = new SqlDataAdapter("select * from forum_answers where Questionid = @questionid", connstring);
                    dadapter.SelectCommand.Parameters.AddWithValue("@questionid", querystr);
                    dset = new DataSet();
                    adsource = new PagedDataSource();
                    dadapter.Fill(dset);
                    adsource.DataSource = dset.Tables[0].DefaultView;
                    adsource.PageSize = 7;
                    adsource.AllowPaging = true;
                    adsource.CurrentPageIndex = pos;
                    btnfirst.Enabled = !adsource.IsFirstPage;
                    btnprevious.Enabled = !adsource.IsFirstPage;
                    btnlast.Enabled = !adsource.IsLastPage;
                    btnnext.Enabled = !adsource.IsLastPage;
                    Datalist1.DataSource = adsource;
                    Datalist1.DataBind();
                }
            }
       
        catch(Exception ex)
         {
             Response.Write(ex.ToString());
       Response.Redirect("Error_Page.aspx");
 
         }
 
        }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try the following Code
 

 
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="5" EnableViewState="true" Width="88%">
  <itemtemplate>Xyz </itemtemplate>
    
 
 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ ConnectionStrings:ConnString %>'SelectCommand="SELECT x,y,z ...">
         
                    <tr>
                        <td>
                              <asp:Label ID="lblCurrentPage" runat="server" Visible="true">
                        </td>
                    </tr>
                    <tr>
                        <td align="center">
                              <asp:Button ID="cmdPrev" runat="server" Text=" << " OnClick="cmdPrev_Click">
                            
                             <asp:Button ID="cmdNext" runat="server" Text=" >> " OnClick="cmdNext_Click">
                            
                        </td>
                    </tr>
 

in the code behind :
 
 protected void items()
    {
        PagedDataSource objDs = new PagedDataSource();
        DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
        objDs.DataSource = dv;
        objDs.AllowPaging = true;
        objDs.PageSize = 20;
        objDs.CurrentPageIndex = CurrentPage;
        lblCurrentPage.Text = "Page:" + (CurrentPage + 1).ToString() + " Of " + objDs.PageCount.ToString();
        cmdPrev.Enabled = !objDs.IsFirstPage;
        cmdNext.Enabled = !objDs.IsLastPage;
        DataList1.DataSource = objDs;
       DataList1.DataBind();
 
    }
 
 
protected void cmdPrev_Click(object sender, EventArgs e)
    {
        try
        {
            CurrentPage -= 1;
            items();
        }
        catch (Exception ex)
        {
            Logger.LogException(ex);
        }
    }
 
    protected void cmdNext_Click(object sender, EventArgs e)
    {
        try
        {
 
            CurrentPage += 1;
            items();
        }
        catch (Exception ex)
        {
            Logger.LogException(ex);
        }
    }
 
[Edit - disabled Treat my content as plain text, not as HTML option]
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Grid view
 

 
AllowPaging="True" PageSize="5"  AllowSorting="true"
 

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            FillGrid();
 
        }
  Permalink  
Comments
Ashika s at 26-Jun-12 7:38am
   
question is for datalist not gridview. please read the question and answer?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Go through below link
 
http://forums.asp.net/t/1108198.aspx[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 30 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100