Asp.net Datapager恢复为原始数据
我创建了一个链接到数据库的搜索页面,当页面加载时,我使用VB Codebehind为Asp.net Datapager恢复为原始数据,asp.net,vb.net,listview,Asp.net,Vb.net,Listview,我创建了一个链接到数据库的搜索页面,当页面加载时,我使用VB Codebehind为ListView设置SqlSelectCommand,这样当客户端搜索某个项目时,我将Sql选择更改为如“%search%” 这一切都很好,但当您单击第2页时,它会恢复到原始sql语句 我对标题使用了标签,我还根据搜索键动态更改标题,以确保数据返回到页面 你可以在这里预览我的网站 Office页面上也存在同样的问题,虽然我在这里以sql select中的数据开始页面,但当我单击例如economy,然后尝试转到第
ListView
设置SqlSelectCommand
,这样当客户端搜索某个项目时,我将Sql选择更改为如“%search%”
这一切都很好,但当您单击第2页时,它会恢复到原始sql语句
我对标题使用了标签
,我还根据搜索键动态更改标题,以确保数据返回到页面
你可以在这里预览我的网站
Office页面上也存在同样的问题,虽然我在这里以sql select中的数据开始页面,但当我单击例如economy,然后尝试转到第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>
我只是猜测listview分页中存在的问题。请检查在重新绑定页面上的listview PropertiesChange事件时使用的查询,如下所示
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中查找有关分页的更多详细信息