Click here to Skip to main content
12,068,520 members (66,125 online)
Rate this:
 
Please Sign up or sign in to vote.
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>


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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160208.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2016
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