How to get this DataList with the paging property?
<p>I am a new ASP.NET developer and I am developing a web-based application in which I have a DataList and I need to have a paging feature. I followed what is explained in this post in the CodeProject, but it did not work with me and I got this error which I could not be able to understand it.</p>

<p><strong>Error:</strong></p>

<blockquote>
  <p>The name 'CurrentPage' does not exist in the current context.</p>
</blockquote>

<p><strong>So how to fix this error  and get the Paging feature in this DataList?</strong></p>

<p>ASP.NET code:</p>

<pre><code>&lt;tr&gt;
            &lt;td width="100%"&gt;
                &lt;asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource2" &gt;
                                &lt;ItemTemplate&gt;
                                    &lt;asp:HyperLink
                                            ID="HyperLink1" runat="server" NavigateUrl='&lt;%# "StartQuiz.aspx?testid=" + Eval("QuizID") %&gt;'
                                            Text='&lt;%# Eval("Title") %&gt;'&gt;&lt;/asp:HyperLink&gt;&lt;br /&gt;
                                    &amp;nbsp;&lt;asp:Label
                                        ID="DescriptionLabel" runat="server" CssClass="generaltext" Text='&lt;%# Eval("Description") %&gt;'&gt;&lt;/asp:Label&gt;&amp;nbsp;&lt;br /&gt;
                                    &lt;br /&gt;
                                &lt;/ItemTemplate&gt;
                            &lt;/asp:DataList&gt;
                &lt;asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="&lt;%$ ConnectionStrings:testConnectionString %&gt;"
                                SelectCommand="SELECT [Title], [Description], [QuizID],[IsSent] FROM [Quiz] where [IsSent]=1 order by [QuizID] DESC"&gt;
                &lt;/asp:SqlDataSource&gt;
            &lt;/td&gt;
        &lt;/tr&gt;                                         

        &lt;tr&gt;
            &lt;td&gt;
                &lt;asp:Label ID="lblCurrentPage" runat="server" Visible="true"&gt;&lt;/asp:Label&gt;
            &lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
            &lt;td align="center"&gt;
                &lt;asp:Button ID="cmdPrev" runat="server" Text=" &lt;&lt; " OnClick="cmdPrev_Click" /&gt;
                &lt;asp:Button ID="cmdNext" runat="server" Text=" &gt;&gt; " OnClick="cmdNext_Click" /&gt;

            &lt;/td&gt;
        &lt;/tr&gt;
</code></pre>

<p>Code-Behind:</p>

<pre><code>protected void items()
    {
        PagedDataSource objDs = new PagedDataSource();
        DataView dv = (DataView)SqlDataSource2.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);
        }
    }
</code></pre>
