Implementing search with custom paging

ben_ng

Member
Joined
Sep 13, 2007
Messages
18
Location
Singapore
Programming Experience
1-3
Hi,
I am trying out this tutorial found here : http://msdn2.microsoft.com/en-us/library/bb445510.aspx#aspnett25cstpgvb_topic4
on implementing custom paging using dal and gridview.
However,I tried changing it slightly by putting a textbox to do some filtering instead of returning the full database.
As a result, my BLL for returning products paged will look like this :
VB.NET:
    <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, False)> _
    Public Function GetProductsPaged(ByVal startRowIndex As Integer, ByVal maximumRows As Integer,ByVal searchword As String) As Northwind.ProductsDataTable
        Return Adapter.GetProductsPaged(startRowIndex, maximumRows,searchword)
    End Function
This is how my page look like :
VB.NET:
<form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Search" /><br />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID"
            DataSourceID="ObjectDataSource1" AllowPaging="True">
            <Columns>
                <asp:BoundField DataField="ProductName" HeaderText="Product" SortExpression="ProductName" />
                <asp:BoundField DataField="CategoryName" HeaderText="Category" ReadOnly="True" SortExpression="CategoryName" />
                <asp:BoundField DataField="SupplierName" HeaderText="Supplier" SortExpression="SupplierName" />
                <asp:BoundField DataField="QuantityPerUnit" HeaderText="Qty/Unit" SortExpression="QuantityPerUnit" />
                <asp:BoundField DataField="UnitPrice" DataFormatString="{0:c}" HeaderText="Price"
                    HtmlEncode="False" SortExpression="UnitPrice" />
            </Columns>
    </asp:GridView>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
            SelectMethod="GetProductsPaged" TypeName="ProductsBLL" EnablePaging="True" SelectCountMethod="TotalNumberOfProducts">
            <SelectParameters>
                <asp:ControlParameter ControlID="TextBox1"  Name="searchword"
                    PropertyName="Text" />
            </SelectParameters>
        </asp:ObjectDataSource>
</form>
Running the code will return this error : ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'GetProductsPaged' that has parameters: searchword.

Been trying this for days,but could not find the problem. Could someone pls help? Thanks!
 
For SelectParameters of ObjectDataSource there is only added the searchword parameter, missing startRowIndex and maximumRows. Since this is generated you should go over the steps again, checking configuration of SP, TA and ObjectDataSource.
 
Hi,
I thought the startRowIndex and MaximumRows are set here ?
Bb445510.aspnet_tutorial25_custompaging_vb_figure16(en-us,MSDN.10).gif
 
Yes, that was a bit fast on the trigger here. You have to add a "TotalNumberOfProductsFiltered" (or modify the TotalNumberOfProducts) query and corresponding BLL method to take same filter parameter. There is an article Filtering Custom Paged Results that explains the same thing.
 
Yes, that was a bit fast on the trigger here. You have to add a "TotalNumberOfProductsFiltered" (or modify the TotalNumberOfProducts) query and corresponding BLL method to take same filter parameter. There is an article Filtering Custom Paged Results that explains the same thing.

Hi John,
the link you gave did it! Used the whole day, but solved my problem. Thanks!
 
Back
Top