[RESOLVED]datapager only works on the second click

HI,

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" >
                <LayoutTemplate>
                    <ul>
                        <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
                    </ul>

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

                </LayoutTemplate>

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

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

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

                    </li>
                </ItemTemplate>
                <EmptyItemTemplate>
                    <li>No data Found
                    </li>
                </EmptyItemTemplate>
            </asp:ListView>

here’s my code behind code

protected void Page_Load(object sender, EventArgs e)
{
            if (!IsPostBack)
            {
                BindListViewControls();
}
}

        
protected void DataPager_PreRender(object sender, EventArgs e)
{
BindListViewControls();
}

Thanks!

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"
OnPagePropertiesChanging="list_PagePropertiesChanging">

and now works fine ;)

Leave a Reply