In a GridView how do you search for an item and set the GridView1.PageIndex accordingly?

S

S_K

Hi,

I have a GridView that displays multiple pages.

I also have a TextBox where the user can input an ID (one of the
GridView column values).

I would like to use this TextBox.Text value to search the GridView for
that ID and set the
GridView.PageIndex so that this value is contained in the new page
that's now displayed.

There must be an easy way of doing this! Any ideas?

Thanks in advance.
Steve
 
G

Guest

Hi,

I have a GridView that displays multiple pages.

I also have a TextBox where the user can input an ID (one of the
GridView column values).

I would like to use this TextBox.Text value to search the GridView for
that ID and set the
GridView.PageIndex so that this value is contained in the new page
that's now displayed.

There must be an easy way of doing this! Any ideas?

Thanks in advance.
Steve


Hi Steve

you can do something like this

-----------------------------------------------

Protected Sub BindGrid()

Dim dr As Data.DataSet = ...

Dim dv As New DataView()
dv = dr.Tables(0).DefaultView

If TextBox.Text.Length > 0 Then

Dim i As Integer = dv.Find(tbSearch.Text)

If i >= 0 Then
GridView.CurrentPageIndex = i \ GridView.PageSize
GridView.SelectedIndex = i
Else
GridView.SelectedIndex = 0
End If

....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top