Filtered 'Top 25' Lookup Grid

Often, lookups are simple. But in some cases, the table that we're doing the lookup against is too big to display in a web page, especially a mobile device. 

This is a template for a web lookup that displays a grid, and filter fields to narrow down the data to select from. In our example the data will be an item lookup against a table with 25k records. 

This is what the page will look like. There is a 'top 25' grid, and the user will enter text in the two text boxes and the grid will filter down. 

Layout for the grid:

<table>
    <tr>
        <td>
            Item Number Filter
        </td>
        <td>
            <telerik:RadTextBox runat="server" ID="txtItemNumberFilter" MaxLength="31" AutoPostBack="true"></telerik:RadTextBox>
        </td>
    </tr>
    <tr>
        <td>
            Item Description Filter
        </td>
        <td>
            <telerik:RadTextBox runat="server" ID="txtItemDescriptionFilter" MaxLength="65" AutoPostBack="true"></telerik:RadTextBox>
        </td>
    </tr>
</table>
 
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" Width="800px" MasterTableView-CommandItemSettings-ShowAddNewRecordButton="false" AllowSorting="true"  >
    <MasterTableView DataKeyNames="itemnmbr, itemdesc"  >
        <Columns>
            <telerik:GridButtonColumn DataTextField="itemnmbr" UniqueName="itemnmbr" HeaderText="" CommandName="Select"   ></telerik:GridButtonColumn>
            <telerik:GridBoundColumn DataField="itemdesc" HeaderText="Item Description"  ></telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

Code behind:

Private Sub RadGrid1_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
    Dim strError As String = ""
    Try
 
        Dim strItemNumberFilter As String = txtItemNumberFilter.text
        Dim strItemDescriptionFilter As String = txtItemDescriptionFilter.text
 
        RadGrid1.DataSource = SPs.fp_IV00101_SEL_Top25(strItemNumberFilter, strItemDescriptionFilter, App.IsAdmin, App.ConnectionString).getTable
    Catch ex As Threading.ThreadAbortException
    Catch ex As Exception
        ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, False)
        Me.lblError.Text = ex.Message
    End Try
 
End Sub
Private Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
 
    Dim strError As String = ""
    Try
        If TypeOf e.Item Is GridDataItem Then
            Select Case e.CommandName
                Case "Select"
                    Dim strItemNumber As String = RadGrid1.MasterTableView.DataKeyValues(e.Item.ItemIndex)("itemnmbr").ToString
                    Session("ItemNumber") = strItemNumber
                    Response.Redirect("item.aspx")
            End Select
        End If
 
    Catch ex As Threading.ThreadAbortException
    Catch ex As Exception
        ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, False)
        Me.lblError.Text = ex.Message
    End Try
 
End Sub
 
Private Sub txtItemDescriptionFilter_TextChanged(sender As Object, e As EventArgs) Handles txtItemDescriptionFilter.TextChanged
    RadGrid1.Rebind()
End Sub
 
Private Sub txtItemNumberFilter_TextChanged(sender As Object, e As EventArgs) Handles txtItemNumberFilter.TextChanged
    RadGrid1.Rebind()
End Sub

 

Stored Procedure:

IF EXISTS (
  SELECT *
    FROM INFORMATION_SCHEMA.ROUTINES
   WHERE SPECIFIC_SCHEMA = N'dbo'
     AND SPECIFIC_NAME = N'fp_IV00101_SEL_Top25'
)
   DROP PROCEDURE dbo.fp_IV00101_SEL_Top25
GO
CREATE OR ALTER PROCEDURE fp_IV00101_SEL_Top25
@ItemNumberFilter VARCHAR(31),
@ItemDescFilter VARCHAR(65)
 
AS
 
SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
 
SELECT TOP 25 itemnmbr, i.itemdesc
    FROM iv00101 i
    WHERE i.INACTIVE = 0
        AND i.itemtype IN (1)
        AND i.itemnmbr LIKE '%' + @ItemNumberFilter + '%'
        AND i.itemdesc LIKE '%' + @ItemDescFilter + '%'
    ORDER BY i.ITEMNMBR
 
GO
Grant EXEC on fp_IV00101_SEL_Top25 to public

 

 

 

 

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences