473,378 Members | 1,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Search Filter!

AJ
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
Nov 19 '05 #1
2 1338
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();
--
Thanks
Kiran Kumar Pinjala
"AJ" wrote:
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

Nov 19 '05 #2
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

"AJ" wrote:
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

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: N. Graves | last post by:
Hi, I want to have a Search Dialog box that has several text box and fields to build a search and display the results in a form. I can do everything that I need to if I us a report but I would...
9
by: Christopher Koh | last post by:
I will make a form which will search the database (just like google interface) that will look/match for the exact name in the records of a given fieldname. Any suggestions on how to make the code?
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
2
by: Homey! | last post by:
Hello all I am new to Access. I have imported data from an old FoxPro 2.x database. This is probably the most basic function but I cant get a search box to work. I need to search for company name...
23
blyxx86
by: blyxx86 | last post by:
I am trying to filter multiple entries with only one search box. That way the user can type whatever they want and find all the values that contain what they enter. Private Sub...
3
by: Elainie | last post by:
I would like to search a form with many fields on it, with out using the search facility through access. Througth a drop down list if possible.... How would I go about this? How could I also...
1
by: Reef81 | last post by:
Does anyone know a way to have the search parameters displayed in the query or report? For example, if I set up a parameter to search all entries in my table, is there a way to have the search...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
2
by: woodey2002 | last post by:
Hi Guys and thanks for your time. I have a search form for my database that allows users to select multiple criteria from multi select list boxes. I successfully integrated a multi select...
6
by: woodey2002 | last post by:
Hi Everyone. Thanks for your time. I am trying to create a search form that will allow users to select criteria from multiple multi select boxes. So far i have managed to achieve a search option...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.