我的Listview上的寻呼机无法运行Asp.net C# [英] Pager on my Listview not working Asp.net C#

查看:87
本文介绍了我的Listview上的寻呼机无法运行Asp.net C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误 - 当我点击下一步按钮后点击上一步按钮,或者当我点击最后一个按钮时,我得到这个错误消息,并且在任何情况下它都不会记录我的记录列表 -





无法加载viewstate。正在加载视图状态的控制树必须与在上一个请求期间用于保存视图状态的控制树匹配。例如,在动态添加控件时,在回发期间添加的控件必须与初始请求期间添加的控件的类型和位置相匹配。



Error-- when i click on Previous button after click on Next button ,or when i click on last button this error message i get and in ever scenario it doesnot Page my List of records--


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.

 <asp:ListView ID="ListJobs" runat="server">
   <LayoutTemplate>
      <table style="border: solid 2px #336699; width:800px; " cellspacing="0" cellpadding="3" rules="all">
         <tr style="background-color: #336699; color: White;">
            <th> Posted Date </th>
            <th> Jobtitle </th>
            <th> Location </th>
         </tr>        
         
         <tr>
            <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
         </tr>
         
                  
         <tr id="Tr2"  runat="server" class="TablePager">  
                        <td id="Td4"  runat="server" colspan="3">  
                            <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListJobs" PageSize="3">  
                                <Fields>  
                                    <asp:NextPreviousPagerField   

                                        ButtonType="Button"   

                                        ShowFirstPageButton="true"  

                                        ShowNextPageButton="true"  

                                        ShowPreviousPageButton="false"  

                                        ButtonCssClass="ButtonCSS"  

                                        />  
                                    <asp:NumericPagerField   

                                        NumericButtonCssClass="NumericButtonCSS"  

                                        CurrentPageLabelCssClass="CurrentPageLabelCSS"  

                                        NextPreviousButtonCssClass="NextPreviousButtonCSS"  

                                        />  
                                    <asp:NextPreviousPagerField   

                                        ButtonType="Button"  

                                        ShowLastPageButton="true"  

                                        ShowNextPageButton="false"  

                                        ButtonCssClass="ButtonCSS"  

                                        />  
                                </Fields>  
                            </asp:DataPager>  
                        </td>  
                    </tr>         
        
      </table>  
   </LayoutTemplate>
   <ItemTemplate>
      <tr>
         <td   style=" width:150px;" ><%# Eval("CreatedDate")%></td>
         <td  style=" width:500px;" > <a href='<%#"JobDetail.aspx?Name="+Eval("Job_Id")%>'</a><%# Eval("JobTitle")%></td>
         <td  style=" width:150px;"><%# Eval("Location")%></td>
      </tr>
   </ItemTemplate>
   <AlternatingItemTemplate>
      <tr style="background-color: #dadada;">         
         <td   style=" width:150px;" ><%# Eval("CreatedDate")%></td>
         <td  style=" width:500px;" > <a href='<%#"JobDetail.aspx?Name="+Eval("Job_Id")%>'</a><%# Eval("JobTitle")%></td>
         <td  style=" width:150px;"><%# Eval("Location")%></td>
      </tr>
   </AlternatingItemTemplate>
   
   <EmptyDataTemplate>
       No Record Found 
   </EmptyDataTemplate>
</asp:ListView>

推荐答案

Use DataPager like this article Effective paging with List View control in ASP.NET[^]
Use DataPager like this article Effective paging with List View control in ASP.NET[^]


The problem is due to the binding occuring on t he Page_Load event.



For this to work as expected, the binding needs to happen in the DataPager’’s OnPreRender event, not in the Page_Load.



Source:

The problem is due to the binding occuring on the Page_Load event.

For this to work as expected, the binding needs to happen in the DataPager''s OnPreRender event, not in the Page_Load.

Source:
<asp:DataPager ID="ListPager" PagedControlID="MyList" runat="server" PageSize="10"
    OnPreRender="ListPager_PreRender">

<Fields>
        <asp:NumericPagerField  />
    </Fields>
</asp:DataPager>







Code Behind:




Code Behind:

protected void Page_Load(object sender, EventArgs e)
{
    //Binding code moved from Page_Load
    //to the ListView''s PreRender event
}

protected void ListPager_PreRender(object sender, EventArgs e)
{
    MyList.DataSource = GetSomeList();
    MyList.DataBind();
}


这篇关于我的Listview上的寻呼机无法运行Asp.net C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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