[RESOLVED]datapager only works on the second click


So i am creating a datapager for my listview, but i can only advance pages on second click

What’s wrong on my code?

.aspx file

<asp:ListView ID="list" runat="server" ItemPlaceholderID="itemPlaceholder" >
                        <asp:PlaceHolder ID="itemPlaceholder" runat="server" />

                    <asp:DataPager ID="pager" runat="server" PagedControlID="list"
                        PageSize="5" OnPreRender="DataPager_PreRender">
                            <asp:NumericPagerField PreviousPageText="<--" NextPageText="-->" />


                    <hr />
                    <li class="cnnews">
                        <div style="display: inline;">
                            <div style='float: right;'><b><%# Eval("date_news")%></b></div>

                            <asp:HyperLink ID="lbltitle_news" runat="server" CssClass="link3" Font-Size="16" Text='<%# Eval("title_news")%>'
                                NavigateUrl='<%# "~/News.aspx?idnews=" + (int)Eval("id_news") %>'></asp:HyperLink>

                        <br />
                        <asp:Label ID="lblresume_news" runat="server"><%# Eval("title_news")%></asp:Label>

                    <li>No data Found

here’s my code behind code

protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)

protected void DataPager_PreRender(object sender, EventArgs e)


I would suggest you to use AspNetPager rather using pager.

You can easily design it. It has more option than Pager and do efficient paging. You just need to pass counter and set few basic setting than it start working

See Demo site

Thanks Guys. I solved the problem i need to add

<asp:ListView ID="list" runat="server" ItemPlaceholderID="itemPlaceholder"

and now works fine ;)

Leave a Reply