| | |
Filtering a GridView by A Name and Two Dates
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 1
Reputation:
Solved Threads: 0
I have a GridView, bound to a SqlDataSource. The SqlDataSource points to a table with seveeral fields, including an Activity Date field and a Name field.
By default I want it to display every entry in the table, but I want to be able to dynamically filter it with three possible variables: A Before date, an After date, and a Name, all of which are selected from separate DropDown lists. For example, if a user picks a Before Date, I want to filter out all entries with dates prior to the Before Date. If the user selects an After date, I want to filter out all entries with dates later than the After date. If both are selected, then both. And at any time, I want to limit all entries to those with the specified Name.
I have written the following Filter Expression:
'(0)' = A Name selected value of a DropDownList.
'{1}' = Date,, which is selected on a Calendar and written to a Field.
'{2}' = Date, which is selected on a Calendar and written to a Field.
The problem is this: Dates are only applied to the Filter if a Name has already been selected. Ex. If I pick Before and After dates, nothing happens, but if I then pick a Name, then all three are applied. If I pick a Name first, it is applied. Any Dates I select after that are also applied.
Why would it be working this way, and is there a better method than that which I am using?
By default I want it to display every entry in the table, but I want to be able to dynamically filter it with three possible variables: A Before date, an After date, and a Name, all of which are selected from separate DropDown lists. For example, if a user picks a Before Date, I want to filter out all entries with dates prior to the Before Date. If the user selects an After date, I want to filter out all entries with dates later than the After date. If both are selected, then both. And at any time, I want to limit all entries to those with the specified Name.
I have written the following Filter Expression:
VB.NET Syntax (Toggle Plain Text)
[Name] = '(0}' AND [Activity Date] > '{1}' AND [Activity Date] < '{2}'
'(0)' = A Name selected value of a DropDownList.
'{1}' = Date,, which is selected on a Calendar and written to a Field.
'{2}' = Date, which is selected on a Calendar and written to a Field.
The problem is this: Dates are only applied to the Filter if a Name has already been selected. Ex. If I pick Before and After dates, nothing happens, but if I then pick a Name, then all three are applied. If I pick a Name first, it is applied. Any Dates I select after that are also applied.
Why would it be working this way, and is there a better method than that which I am using?
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Generating Random Numbers
- Next Thread: StreamReader and Position (In VB)
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2005 2008 access account application arithmetic array arrays basic bing button buttons c# center check checkbox code convert crystalreport data database datagrid datagridview date dissertation dissertations dropdownlist excel fade file-dialog filter ftp generatetags google gridview hardcopy images inline input insert intel internet listview mobile monitor ms net networking objects output panel passingparameters picturebox picturebox1 port position print printing problem project read remove save searchbox searchvb.net select serial shutdown soap sorting survey table tcp temperature text textbox timer timespan toolbox trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio2008 web webbrowser winforms wpf year





