Click here to Skip to main content
15,907,395 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am facing trouble with paging in datalist.
I have two table one is tblQuestion fields are qid,question,creationdate
and the second table is tblAnswerChoice fields are ansid, qid,answeroptions.

Now i have to show the record from both table in datalist
And I have to show 1 record at one time.

Main twist is I have to show the record according to creation date

All the data added on same date will be displayed in datalist .

I need paging in datalist with one record at one time with next and previous button



THanks,
Deepak
Posted

see this link

datalist Paging in asp.net[^]
 
Share this answer
 
 
Share this answer
 
 
Share this answer
 
Reffer this:
http://forums.asp.net/t/1108198.aspx[^]

or try the following :

ASP.NET
<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 :


C#
 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);
        }
    }
 
Share this answer
 
v5
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900