2013-04-05 44 views
0

我做了一個搜索頁面鏈接到數據庫,當頁面加載時我使用VB Codebehind設置SqlSelectCommandListView所以它返回0結果,當客戶端搜索一個項目我改變Sql選擇爲LIKE '%search%'Datapager回覆原來的數據

這一切工作正常,但發生的事情是,當你點擊第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

我只是猜測你在listview分頁問題。請按照以下方式檢查您在重新處理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(); 
} 

請在下面的鏈接中找到關於分頁的更多細節。

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