0

我创建了一个链接到数据库的搜索页面,当页面加载时,我使用 VB Codebehind 设置它SqlSelectCommandListView因此它返回 0 结果,当客户端搜索项目时,我将 Sql 选择更改为LIKE '%search%'.

这一切都很好,但发生的情况是,当您单击第 2 页时,它会恢复为原始 sql 语句

我正在使用一个Label标题,我也根据搜索键动态更改以确保将数据返回到页面

你可以在这里预览我的网站 http://www.barkingdog.co.za/asp/Search1.aspx

同样的问题在Office页面上,虽然我用sql select中的数据开始页面,但是当我点击例如。经济然后尝试转到第2页它显示原始内容的第2页

先感谢您

VB

Protected Sub SearchBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles SearchBox.TextChanged
    Dim nval As String
    nval = Searchbox.Text
    BreadCrumb.Text = "Results for " + nval

    AllProductsOff.SelectCommand = "SELECT * FROM [cxpproducts] WHERE [Range]  LIKE '%" & nval & "%'"
End Sub

Protected Sub SearchButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SearchButton.Click
    Dim nval As String
    nval = Searchbox.Text
    BreadCrumb.Text = "Results for " + nval

    AllProductsOff.SelectCommand = "SELECT * FROM [cxpproducts] WHERE [Range]  LIKE '%" & nval & "%'"
End Sub

ASP

  <asp:TextBox ID="SearchBox" runat="server" 
    AutoPostBack="True"></asp:TextBox>

  <asp:Button ID="SearchButton" runat="server" 
    Text="Search" PostBackUrl="./Search1.aspx" style="margin-top: 0px" />

列表显示

 <LayoutTemplate>
   <div style="" align="center">
     <asp:DataPager ID="DataPager2" runat="server">
       <Fields>
         <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True" 
                        ShowNextPageButton="True" ShowPreviousPageButton="True" NextPageText=">>" LastPageText="Last" PreviousPageText="<<" />
         <asp:NumericPagerField />
         <asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="True" 
                        ShowNextPageButton="False" ShowPreviousPageButton="False" />
       </Fields>
     </asp:DataPager>
   </div>
   <div ID="itemPlaceholderContainer" runat="server" class="style25">
     <span runat="server" id="itemPlaceholder" />
   </div>
   <div style="" align="center">
     <asp:DataPager ID="DataPager1" runat="server">
       <Fields>
         <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                        ShowNextPageButton="False" ShowPreviousPageButton="False" NextPageText=">>" PreviousPageText="<<" />
         <asp:NumericPagerField />
       </Fields>
     </asp:DataPager>
   </div>
 </LayoutTemplate>
4

1 回答 1

0

我只是在你的列表视图分页中猜测这个问题。请检查您在重新绑定 PagePropertiesChanging 事件上的列表视图时使用的查询,如下所示。

protected void ListView1_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
    //set current page startindex, max rows and rebind to false
    lvDataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);

    //rebind List View
    BindListView();
}

请在以下链接中找到有关 Listview 中分页的更多详细信息。

http://dotnet.dzone.com/articles/paging-listview-using

于 2013-04-05T09:40:18.710 回答