当前位置:编程学习 > C#/ASP.NET >>

DataPager 翻页无效

通过 数字按钮 可进行 翻页
但通过 “下一页”按钮进行翻页时,无法查看页数大于等于3的页中的内容。
请问该如何解决??
前台:
 <asp:DataList ID="DataList1" runat="server"  
        onitemdatabound="DataList1_ItemDataBound" CellPadding="4" 
        ForeColor="#333333">
    
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <AlternatingItemStyle BackColor="White" ForeColor="#284775" />
        <ItemStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    
    <HeaderTemplate>
    <table style="width:900px;" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td style="width:100px;" align="center">
                        商品编码</td>
                    <td style="width:500px;" align="center">
                        商品名称</td>
                    <td style="width:300px;" align="center">
                        商品规格</td>
                </tr>
                <tr>
                  <td colspan="3">
                    <table border="0" cellpadding="0" cellspacing="0"  width="900px">
                      <tr>
                        <td  style="width:20px"></td>
                        <td  style="width:500px" align="center">供应商名称</td>
                        <td  style="width:100px" align="center">数量</td>
                        <td  style="width:100px" align="center">单价</td>
                        <td  style="width:180px" align="center">日期</td>
                      </tr>
                    </table>
                  </td>
                </tr>
        
    </HeaderTemplate>
        <ItemTemplate>
        
                <tr onclick="disnoe('aa<%#Eval("aa") %>'); " style="background-color:Teal;">
                    <td class="style2"  style="width:100px;" >
                    <asp:Label ID="spmc" Runat="server" Text=' <%#Eval("aa") %>' Width="100px">
                       </asp:Label>
                    </td>
                    <td class="style1"  style="width:500px;">
                       <%#Eval("bb") %>
                    </td>
                    <td  style="width:300px;">
                       <%#Eval("cc") %>
                    </td>
                </tr>
                
               <tr id='aa<%#Eval("aa") %>' style=" height:0px;  background-color:Olive ;">
                 <td colspan="3">
                   <table width="100%" border="0" cellpadding="0" cellspacing="0"  style="margin-left:30px;">
                     <tr>
                      <td style="width:40px;"></td>
                      <td  style=" width:100%">
                   <%--   <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  Width="900px" RowStyle-Height="5px"
                              BorderWidth="1px"    Height="0px"   
                          CellPadding="4" ForeColor="#333333" ShowHeader="False" Font-Size="X-Small">
                         <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                         <Columns>
                             <asp:ImageField DataImageUrlField="img">
                                 <ItemStyle Width="20px" />
                             </asp:ImageField>
                             <asp:BoundField DataField="CompanyName" HeaderText="供应商名称"   >
                                 <ItemStyle Width="500px"  Wrap="true" />
                             </asp:BoundField>
                             <asp:BoundField DataField="BuyQTY" HeaderText="购买数量" >
                                 <ItemStyle Width="100px" />
                             </asp:BoundField>
                              <asp:BoundField DataField="ActPrice" HeaderText="含税单价" >
                                  <ItemStyle Width="100px" />
                             </asp:BoundField>
                              <asp:BoundField DataField="CreateDate" HeaderText="购买日期" >
                                  <ItemStyle Width="180px" />
                             </asp:BoundField>
                         </Columns>
                          
                         <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                         <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                         <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                         <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                         <EditRowStyle BackColor="#999999" />
                         <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                      </asp:GridView>       --%>
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
                        
                          <asp:ListView runat="server" ID="_易做图TableListView"   
                              DataSourceID="SqlDataSource1" 
                              onpagepropertieschanged="_易做图TableListView_PagePropertiesChanged" 
                              onpagepropertieschanging="_易做图TableListView_PagePropertiesChanging"  > 
                              <LayoutTemplate>    
                               <table>  
                                <tbody>
                                    <asp:PlaceHolder runat="server" ID="itemPlaceholder" />
                                </tbody>    
                                </table>  
                                </LayoutTemplate>  
                                <ItemTemplate>    
                                <tr >   
                                        <td style="width:20px;  color:Black;"><asp:Image ID="image"  runat="server"  ImageUrl='<%# Eval("img1")%>' ></asp:Image></td>  
                                        <td  style="width:500px" ><%# Eval("CompanyName")%></td>  
                                        <td style="width:100px"><%# Eval("BuyQTY")%></td>  
                                        <td  style="width:100px"><%# Eval("ActPrice")%></td>  
                                        <td  style="width:180px"><%# Eval("CreateDate")%></td>                        
                                </tr> 
                                 </ItemTemplate>
                             </asp:ListView>
                          <asp:DataPager ID="DataPager1" runat="server" 
                              PagedControlID="_易做图TableListView">
                              <Fields>
                                  <asp:NextPreviousPagerField  ShowFirstPageButton="True" ShowLastPageButton="True"  ButtonType="Link" />
                                  <asp:NumericPagerField />
                              </Fields>
                          </asp:DataPager>
                          </td>
                         </tr>
                         </table>
                     </td>
                   </tr>

                          
                        </ItemTemplate>
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <FooterTemplate>
          </table>
        </FooterTemplate>
    </asp:DataList>

后台:
 protected void Page_Load(object sender, EventArgs e)
    {

        DataTable dt = myDB.GetDataTable("select top 5   goodsname bb ,goodsmodel cc ,goodscode aa from goodsinfo", "goodsinfo");

        DataList1.DataSource = dt;
        DataList1.DataBind();
      




    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            //GridView gv = (GridView)e.Item.FindControl("GridView1");
            ListView _易做图TableListView = (ListView)e.Item.FindControl("_易做图TableListView");
            Label lbl=(Label )e.Item.FindControl("spmc");
            SqlDataSource SqlDataSource1 = (SqlDataSource)e.Item.FindControl("SqlDataSource1");

            string cSql = "SELECT top 5000  ' ' img ,'~/images/TREE/Tminus.png' img1 , SupplierInfo.CompanyName,  BuySheet.CreateDate, "
                                             + "  BuySheet.BuyQTY,  BuySheet.ActPrice "
                                             + "  FROM   BuySheet INNER JOIN  SupplierInfo ON "
                                             + "         BuySheet.SupplierCode =  SupplierInfo.CompanyCode"
                                      ; //      +"  WHERE ( BuySheet.GoodsCode!='"+lbl.Text+"') order by  BuySheet.CreateDate desc ";
            DataTable dt = myDB.GetDataTable(cSql, "BuySheet");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["img"] = ResolveUrl("~/images/TREE/Tminus.png");
            }
            SqlDataSource1.SelectCommand = cSql;
            SqlDataSource1.ConnectionString = DCIS.Enviroment.DBConnection.ConnInfo.ConnString;
            _易做图TableListView.DataSourceID = SqlDataSource1.ID.ToString();
            //   _易做图TableListView.DataSource = sds;
            _易做图TableListView.DataBind();


            //gv.DataSource = dt;
            //gv.DataBind();
        }
    }

    protected void _易做图TableListView_PagePropertiesChanged(object sender, EventArgs e)
    {

    }
    protected void _易做图TableListView_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
    {
       
    } listview --------------------编程问答-------------------- 好长。懒得看了。。建议你就从了webdiyer大哥吧,AspNetPager很好用。 --------------------编程问答-------------------- 由于是内部嵌套,所以  不行啊!?
如果 不进行 嵌套 一切都好办多了!

补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,