我创建了一个链接到数据库的搜索页面,当页面加载时我使用VB Codebehind为SqlSelectCommand
设置ListView
,因此当客户端搜索项目时返回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>
答案 0 :(得分:0)
我只是在你的listview分页中猜测这个问题。在PagePropertiesChanging事件重新绑定listview时,请检查您正在使用的查询,如下所示。
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分页的更多详细信息。