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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
myDate =myDate .ToString("MM/DD/YYYY")
ASKER
I get exception
string is not a valid datetime
Lossie
string is not a valid datetime
Lossie
myDate =Convert.ToDateTime(myDate ).ToString ("dd/MM/yy yy")
ASKER
Thank you pradyahuja
I get the same exception.
Perhaps I should ask this as a seperate question?
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?
ASKER
If I select 16 Feb 2010 on the datetimepicker
This is the exception
System.InvalidCastExceptio n was unhandled
Message="Conversion from string "02/16/2010" to type 'Date' is not valid."
This is the exception
System.InvalidCastExceptio
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
try changing date to 02/02/2010
ASKER
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-d d")
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.
So, I try to change the datetimepicker format to match the dataview
myDate = DateTimePicker1.Value.Date
myDate = myDate.ToString("yyyy-MM-d
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...
ASKER
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