Hi all,
I hope someone can help with this relatively simple problem.
I am building a timesheet application using ASP.NET C# with Visual
Studio 2003.As it is only a protoype application, my database has been
made in MSDE.
I have a 'View Resources' page, the purpose of which is to show all
employees, taken from that table in the database. This works fine, up
to a point. I have a DataGrid, which is done with a DataSet and a
DataAdapter. I now want the user to be able to 'filter' the DataGrid,
using a text box for input, and a 'search' button. I have tried
different ways of doing this but can't get it to work. I imagine that
it is achieved by running some kind of different SQL statement (with a
% LIKE % operator) in the btnSearch_Click method, and re-binding the
Data Grid after the filter has finished.
So for example the user could enter 'John' in the 'First Name' text box
and click 'search', and the Data Grid would refresh accordingly with
all records LIKE 'John'.
My Page_Load code looks like this currently
-------------------------------------------------------------------------
this.sqlDataAdapter1.Fill(this.dsResources1);
DataGrid1.DataBind();
sqlConnection2.Close();
this.DataGrid1.PageIndexChanged += new
System.Web.UI.WebControls.DataGridPageChangedEvent Handler(this.GridPageIndexChanged);
--------------------------------------------------------------------------------------------
Hope someone can help, I'm sure the btnSearch_Click method is where I
need to put the code.
Thanks in advance,
Al 9 2731
DataSet11.Employees.DefaultView.RowFilter = " Firstname like '%" &
TextBox1.Text & "%' "
--
Terry Burns http://TrainingOn.net
"thebison" <al************@btinternet.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com... Hi all,
I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my database has been made in MSDE.
I have a 'View Resources' page, the purpose of which is to show all employees, taken from that table in the database. This works fine, up to a point. I have a DataGrid, which is done with a DataSet and a DataAdapter. I now want the user to be able to 'filter' the DataGrid, using a text box for input, and a 'search' button. I have tried different ways of doing this but can't get it to work. I imagine that it is achieved by running some kind of different SQL statement (with a % LIKE % operator) in the btnSearch_Click method, and re-binding the Data Grid after the filter has finished.
So for example the user could enter 'John' in the 'First Name' text box and click 'search', and the Data Grid would refresh accordingly with all records LIKE 'John'.
My Page_Load code looks like this currently ------------------------------------------------------------------------- this.sqlDataAdapter1.Fill(this.dsResources1); DataGrid1.DataBind(); sqlConnection2.Close();
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEvent Handler(this.GridPageIndexChanged); --------------------------------------------------------------------------------------------
Hope someone can help, I'm sure the btnSearch_Click method is where I need to put the code.
Thanks in advance,
Al
Hi Terry,
Thanks for your quick reply. I have tried that code, with some
variations but still cannot quite get the search button to have any
effect on my Data Grid when pressed? In the code below, I have
simplified the requirement to simply return all records with a DeptID
less than 2. Unfortunately it still returns all records in the table?
(Note I am running the Search on the 'Dept' table now, not 'Resource')
-------------------------------------------------------------------
private void btnSearch_Click(object sender, System.EventArgs e)
{
DataView dv = dsDept1.Tables[0].DefaultView;
dv.RowFilter = "DeptID <2";
DataGrid1.DataSource = dv;
DataGrid1.DataBind();
}
----------------------------------------------------------------------------
Any suggestions? I'm sure I am close to getting it to work! Is it
something to do with the fact I have another DataGrid1.DataBind(); in
my Page_Load section of the code?
Thanks again!
Al,
Try this... place a DataView on your page designer, set the Table to
the appropriate table in your DataSet and use the DataView as the
Grid's datasource (you need to add the tables to your DataSet, if you
haven't already).
Then you can use this code like this in your Click event:
newDataView.RowFilter = "DeptID <2";
DataGrid1.DataBind();
I didn't look into the problem you're having, but I suspect the problem
is related to binding to the DataSet in the PageLoad and changing it to
the DataView in the click method. I think you'll find a DataView
created at design makes RowFilters and sorting expressions easier to
use anyway.
Hope this helps,
Carl
Carl,
That works just right! Thanks!
Would you know how I can manipulate the RowFilter to return the rows
based on a user-input textbox?
I've tried something like
dataView1.RowFilter = "DeptName LIKE '%'+txtDeptName.text+'%'";
But this does not work.
Any suggestions?
Thanks for your help
Al
Extra info - the error message for the code above is
Exception Details: System.Data.EvaluateException: Cannot find column
[txtDeptName.text].
This occurs when I click on the 'Search' Button
Thanks!
I showed you how to do this, in my first post, which by the way is a live
working example.
--
Terry Burns http://TrainingOn.net
"thebison" <al************@btinternet.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com... Extra info - the error message for the code above is
Exception Details: System.Data.EvaluateException: Cannot find column [txtDeptName.text].
This occurs when I click on the 'Search' Button
Thanks!
Terry,
Sorry, I confused myself with this! I tried the code you posted, and it
does exactly what I wanted! Thanks a lot!
The next step for me is to apply this principle to make a search on
another form, holding lists of Time Periods with Start and End Dates.
With this search, I need to to possibly search by values from TWO user
text boxes. So in theory the user could search for values between Start
Date 11/01/05 and End Date 30/01/05 OR just search based on ONE of the
two input text boxes. So if the textbox is blank the search will just
ignore it. Does that make sense?
I've googled it, but can't quite find what I'm after
Any help much appreciated.
Al
I think you accidently wrapped txtDeptName.Text in double quotes, so
the literal value is being passed rather than the Text property. Try
this:
dataView1.RowFilter = "DeptName LIKE '%'" + txtDeptName.text + "'%'";
or...
dataView1.RowFilter = string.Format("DeptName LIKE '%{0}%'",
txtDeptName.text);
Glad this worked for you,
Carl
Yes, the SQL syntax is
SELECT column_name FROM table_name
WHERE column_name
BETWEEN value1 AND value2
I have not tried using this in a table, so I would be interested to see if
it works.
= "column_name BETWEEN 01/01/2005 AND 01/01/2006"
let me know
--
Terry Burns http://TrainingOn.net
"thebison" <al************@btinternet.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com... Terry,
Sorry, I confused myself with this! I tried the code you posted, and it does exactly what I wanted! Thanks a lot!
The next step for me is to apply this principle to make a search on another form, holding lists of Time Periods with Start and End Dates. With this search, I need to to possibly search by values from TWO user text boxes. So in theory the user could search for values between Start Date 11/01/05 and End Date 30/01/05 OR just search based on ONE of the two input text boxes. So if the textbox is blank the search will just ignore it. Does that make sense?
I've googled it, but can't quite find what I'm after
Any help much appreciated.
Al This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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?
|
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...
|
by: Luis Ferrao |
last post by:
Comming from Windows Forms development, I never had problems with this
issue before.
What i'm trying to achieve is an iTunes like incremental search. For
those who never used iTunes, it's...
|
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...
|
by: |
last post by:
I have a question about spawning and displaying subordinate list controls
within a list control. I'm also interested in feedback about the design of
my search application. Lots of code is at the...
|
by: =?Utf-8?B?RGFuaWVs?= |
last post by:
Dear All
I need some help. I've got a deadline for this friday and i'm stuck. what
i'm trying to do is have 1 textbox, datagrid and 1 button then when the user
enter a search string, and press...
|
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...
|
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,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |