如何有效地为asp.net中的列表视图控件提供数据分页 [英] how to effectively give data pagination to list view control in asp.net

查看:72
本文介绍了如何有效地为asp.net中的列表视图控件提供数据分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我是初学者,我正在使用asp.net c#创建网站。在我的网站中我使用listview控件,其中我给了数据分页。但我必须单击页面按钮两次才能更改页面。有时我会收到错误无法加载viewstate。正在加载viewstate的控件树必须与用于在上一个请求期间保存viewstate的控制树匹配。例如,在动态添加控件时,在回发期间添加的控件必须与初始请求期间添加的控件的类型和位置相匹配。



以下是我的列表视图控件

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

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();





任何人都可以帮我有效地对listview control进行分页。祝福你



Can anyone please help me to effectively paginate listview control.god bless you

推荐答案

这篇关于如何有效地为asp.net中的列表视图控件提供数据分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆