Link to home
Start Free TrialLog in
Avatar of lossiemouth
lossiemouth

asked on

dataview rowfilter by date

Hi,
I have a dataview with a DATE column which is in Date format (not string)

I have a datetimepicker.

The user selects a date from the datetimepicker.
I want to rowfilter the dataview, so that all rows which have a Date, later than
the selected datetimepicker date, are displayed.

something like:
 myDate = DateTimePicker1.Value.Date
       myView.RowFilter = ("Date <=   myDate ")

The above does not work. I have tried various combinations of the above but no joy.

Any help is greatly appreciated.

Lossie  
ASKER CERTIFIED SOLUTION
Avatar of pradyahuja
pradyahuja
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lossiemouth
lossiemouth

ASKER

Thank you. It now filters but I have a problem with date formats.

The Dataview is taken from a XML table. The date format is YYYY-MM-DD
The datetimepicker has a format of MM/DD/YYYY

This is causing problems with the filter.

Is there a way to change one of the formats, so that they match?

Lossie
myDate =myDate .ToString("MM/DD/YYYY")
I get exception

string is not a valid datetime

Lossie
myDate =Convert.ToDateTime(myDate).ToString("dd/MM/yyyy")
Thank you pradyahuja
I get the same exception.

Perhaps I should ask this as a seperate question?
when this code executes, can u see whats the value of myDate?
If I select 16 Feb 2010 on the datetimepicker
This is the exception

System.InvalidCastException was unhandled
  Message="Conversion from string "02/16/2010" to type 'Date' is not valid."
works fine on my machine.
try changing date to 02/02/2010
The dataview Date column format is yyyy-mm-dd
So, I try to change the datetimepicker format to match the dataview
myDate = DateTimePicker1.Value.Date
myDate = myDate.ToString("yyyy-MM-dd")

When I run this code, myDate = #2/2/2010#
I was hoping for 2010-02-02

However, I could be wrong, but I don't think it would work anyway. because I am now trying to
use a string to rowfilter a Date column.
oh ok...