Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

How to: Search Data in a DataRepeater Control

Visual Studio 2005

When you are using a DataRepeater control that contains many records, you may want to let users search for a specific record. Rather than searching the data in the control itself, you can implement a search by querying the underlying BindingSource. If the item is found, you can then use the CurrentItemIndex property to select the item and scroll it into view.

To implement search

  1. Drag a TextBox control from the Toolbox onto the form that contains the DataRepeater control.

  2. In the Properties window, change the Name property to SearchTextBox.

  3. Drag a Button control from the Toolbox onto the form that contains the DataRepeater control.

  4. In the Properties window, change the Name property to SearchButton. Change the Text property to Search.

  5. Double-click the Button control to open the Code Editor, and add the following code to the SearchButton_Click event handler.

    Private Sub SearchButton_Click(ByVal sender As System.Object, _
     ByVal e As System.EventArgs) Handles SearchButton.Click
        Dim foundIndex As Integer
        Dim searchString As String
        searchString = SearchTextBox.Text
        foundIndex = ProductsBindingSource.Find("ProductID", _
     searchString)
        If foundIndex > -1 Then
            DataRepeater1.CurrentItemIndex = foundIndex
        Else
            MsgBox("Item " & searchString & " not found.")
        End If
    End Sub
    

    Replace ProductsBindingSource with the name of the BindingSource for your DataRepeater, and replace ProductID with the name of the field that you want to search.

Tasks

Concepts

Reference

Other Resources

Troubleshooting the DataRepeater Control
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.