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,
My current project is a real estate website. In this I have to display the details of the properties in small boxes. I did it successfully using data list in rows and columns. But I want to enable paging in data list. I searched in Google and got many codes. But none of that satisfied my requirement.
 
Here is my .aspx code
<table>
<tr>
    <td>
<asp:DataList ID="DataList1" runat="server" DataKeyField="fldId" 
        DataSourceID="SqlDataSource1" RepeatColumns="2" OnSelectedIndexChanged="dlProducts_SelectedIndexChanged">
        <ItemTemplate>
            <asp:Image ID="Image1" runat="server" Height="111px" 
                ImageUrl='<%# Eval("fldImage", "~/Property/{0}") %>' Width="247px" />           
.
.
.
 

        </ItemTemplate>
    </asp:DataList>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        SelectCommand="SELECT [fldId], [fldImage], [fldCategory] FROM [tblMaster]">
        <SelectParameters>
            <asp:Parameter DefaultValue="1" Name="fldAd" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
</td></tr?
<tr>
            <td>
                <asp:Label ID="lblCurrentPage" runat="server" Visible="true"></asp:Label>
            </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>
        </table>
 

I tried this .aspx.cs code, but got the error
"
The name 'CurrentPage' does not exist in the current context.
"
 
.aspx.cs
  protected void items()
    {
        PagedDataSource objDs = new PagedDataSource();
        DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
        objDs.DataSource = dv;
        objDs.AllowPaging = true;
        objDs.PageSize = 5;
        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);
        }
    }
 
How can I remove this error or is there any other methods to apply paging in Datalist? Please give me any ideas to overcome my problem.
Thank you...
Posted 25-Jul-12 20:34pm
Edited 25-Jul-12 21:29pm
v6
Comments
Sandeep Mewara at 26-Jul-12 2:22am
   
You use currentpage everywhere. Where is that defined?
 
Is this your code? Looks like a copy-paste.. from where?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Well, code shared across does not have CurrentPage declaration at all. In order to drive data using pagination, you are using variable 'Currentpage' all through which looks missing. Hence the error.
 
Define the variable, set it at load for first time. Try out.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Mohamed Mitwalli thanking you for this post
  Permalink  

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

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 17 Oct 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