tags:

views:

231

answers:

4

Hi everybody,

I have a standart Page within my ListView control on the page, And the Pager is work, however in order to move to next list of items i required to click on pager link twice before it actually moves to next set of items.

The code for the pager is:

 <asp:ListView ID="lv_LostCard" runat="server" DataKeyNames="request_id" EnableViewState="false">
        <LayoutTemplate>
               <table width="550" border="1" class="table">
                    <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
                </table> 
                <asp:DataPager ID="lv_Books_Pager" runat="server" PageSize="10">
                    <Fields>
                        <asp:NextPreviousPagerField ShowFirstPageButton="false" ShowPreviousPageButton="true" ShowNextPageButton="false" />
                        <asp:NumericPagerField />
                        <asp:NextPreviousPagerField ShowFirstPageButton="false" ShowPreviousPageButton="false" ShowNextPageButton="true" ShowLastPageButton="false" />
                    </Fields>
                </asp:DataPager>
            </LayoutTemplate>
            <ItemTemplate>               
            </ItemTemplate>
    </asp:ListView>

and the Code behind is:

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

 protected void getLostCardsList()
    {
        using(LostCardsManagementDataContext LostCard = new LostCardsManagementDataContext())
        {
            var getLostCardsList = from lc in LostCard.lostcard_request_cards
                                   select lc;
            lv_LostCard.DataSource = getLostCardsList;
            lv_LostCard.DataBind();
        }

Can somebody tell me what happening and how to fix it ?

Thanks in advance

A: 

Are you binding your listview in code? Make sure you are only doing that on non-postbacks.

Andrew Robinson
Yes i do, in my code behind i have if (!Page.IsPostBack), it is really drives me crazy and i have no idea why it behaves that way.
Dmitris
I edited and added my code behind in question as well.
Dmitris
A: 

You have turned off the viewstate on your ListView. Try it with the viewstate back on.

Keltex
+1  A: 

DataBind in the PagePropertiesChanged event.

private void listview_PagePropertiesChanged(object sender, System.EventArgs e)
{
    listview.DataBind();
}
brian
I tried this one but it doesn't work exactly !
Myra
A: 

I have problems with listview sincerely.

I found a solution related to your question which seems there is no other way to fix that.You need to call OnPreRender method to rebind your source to listview.

protected void listview_PreRender(object sender, EventArgs e)
{
    getLostCardsList();//your method for binding
}

Be adviced, PreRender events called before your page is rendered.More clearly,if your page has a postback event will render again.That means you need to store your data into a server collection (i.e. Session).

Myra