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...