Search Filter!

G

Guest

Hi all,

An easy question!

I have a datagrid that can needs to provide filter functionality.

I have three controls above the grid (txtSearch,ddlSearchBy,btnSearch)

btnSearch calls btnSearch_Click.

Here is my code:

Sub btnSearch_Click(ByVal Sender As Object, ByVal e As System.EventArgs)

Dim Dv As New DataView(CType(dgEmps.DataSource,DataTable)
Dv.RowFilter = "first_name like '%b'%"

dgEmps.DataSource = Dv
dgEmps.DataBind()

End Sub

Unfortunately i have had no joy with this code though i know the db contains
a first_name like 'b'.

I am a little tired, so can someone give me a heads up on the best way to
approach this using the DataSet object populating my DataGrid.

Thought: The DataSet for the datagrid is available after first page call is
it?

Cheers,
Adam
 
G

Guest

Here is a thought,
Instead of using the DataSource of the grid to derive the dataView, store
the dataset in a session variable like
Session["ds"] = ds;
and use the dataset to derive the dataview and apply the rowfilter on it.
This has always worked for me. Here is the complete code in C#, You should be
able to easily modify to VB.Net.

DataTable dt = (DataTable)Session["dt"];
DataView dv = dt.DefaultView;
dv.RowFilter = "ProductName Like '%c%'";
PrdGrid.DataSource = dv;
PrdGrid.DataBind();
 
G

Guest

In Framework 1.x, datagrid.DataSource is not available when posting back,
unless you re-bind datagrid’s data source either from re-querying DB or
retrieving from Session (It was saved there in first query).

HTH

Elton Wang
 

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

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top