Click here to Skip to main content
15,905,566 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am a beginner and i am creating website using asp.net c#.In my website i am using listview control in which i gave data pagination. But i had to click page buttons twice to change pages.Also sometimes i would get error "Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request."

Below is my list view control
<asp:ListView ID="ListView2" runat="server" 
            onselectedindexchanged="ListView2_SelectedIndexChanged">
            <LayoutTemplate >
            <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
           
      <asp:DataPager runat="server" ID="DataPager" PageSize="3">
      <Fields>
        <asp:NumericPagerField
          ButtonCount="5"
          PreviousPageText="<--"
          NextPageText="-->" />
      </Fields>
    </asp:DataPager>
   </LayoutTemplate>
   
   <ItemTemplate>
      
     <div class="offer_box_wide_style1"> <img src="<%# Eval("image1") %>" width="130" height="98" class="img_left" alt="" border="0"/>
        <div class="offer_info"> <span>
            <asp:Label ID="Label2" runat="server" Text='<%# Eval("title") %>'></asp:Label>  Price:<asp:Label ID="Label5" runat="server" Text='<%# Eval("price") %>'></asp:Label></span>
          <p class="offer"> 
              <asp:Label ID="Label4" runat="server" Text='<%# Eval("description") %>'></asp:Label> </p>
          <div class="more"><a href="#">...more</a></div>
        </div>
      </div>
       
   </ItemTemplate>
   <EmptyItemTemplate>
            <td id="Td1"  runat="server"></td>
         </EmptyItemTemplate>
    
   </asp:ListView>


Below is the code behind
C#
SqlDataAdapter da = new SqlDataAdapter(cmd, constr);
       DataTable table = new DataTable();

       da.Fill(table);

       DataTable outputTable = table.Clone();

       for (int i = table.Rows.Count - 1; i >= 0; i--)
       {
           outputTable.ImportRow(table.Rows[i]);
       }





       ListView2.DataSource = outputTable;
       ListView2.DataBind();


Can anyone please help me to effectively paginate listview control.god bless you
Posted
Updated 19-Mar-14 1:20am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900