Kerau
asked on
Issues with Date Range Picker
I am working on Date Range Picker where a user can pick specific date and according to the date range (parameter passed) he will be displayed the report. Right now everything works fine untill a user chooses his start date and end date as the same day. eg start date 10/06/2008 and enddate 10/06/2008, the report then errors out.
I want to insert a logic below, if the SelectedBeginDate = SelectedEndDate. I want SelectedEndDate added by a day. Say a user chooses start date 10/06/2008 and enddate 10/06/2008 ..the end date should be converted as 10/07/2008..I have been trying this for couple of hours but in vain...How do i do this?..please advice
I want to insert a logic below, if the SelectedBeginDate = SelectedEndDate. I want SelectedEndDate added by a day. Say a user chooses start date 10/06/2008 and enddate 10/06/2008 ..the end date should be converted as 10/07/2008..I have been trying this for couple of hours but in vain...How do i do this?..please advice
Private Function DateRangeIsValid(ByVal dateRange As DateRangePicker) As Boolean
If (IsNothing(dateRange.SelectedBeginDate) And IsNothing(dateRange.SelectedEndDate)) Then
Return True
Else
If (IsNothing(dateRange.SelectedBeginDate) And Not IsNothing(dateRange.SelectedEndDate)) Or _
(Not IsNothing(dateRange.SelectedBeginDate) And IsNothing(dateRange.SelectedEndDate)) Then
Return False
End If
End If
Return dateRange.SelectedEndDate.Value.Date >= dateRange.SelectedBeginDate.Value.Date
End Function
End Class
http://www.codeproject.com/KB/aspnet/DateRangePicker.aspx
I've never used your control so I don't know if this will work:
(at the very least you can simplify your logic in the beginning like this)
Private Function DateRangeIsValid(ByVal dateRange As DateRangePicker) As Boolean
If IsNothing(dateRange.Select edBeginDat e) AndAlso IsNothing(dateRange.Select edEndDate) Then
Return True ' Both are Nothing
ElseIf IsNothing(dateRange.Select edBeginDat e) OrElse IsNothing(dateRange.Select edEndDate) Then
Return False ' Only one is Nothing
End If
If dateRange.SelectedEndDate. Value.Date = dateRange.SelectedBeginDat e.Value.Da te Then
dateRange.SelectedEndDate. Value = dateRange.SelectedEndDate. Value.AddD ays(1)
End If
Return dateRange.SelectedEndDate. Value.Date >= dateRange.SelectedBeginDat e.Value.Da te
End Function
(at the very least you can simplify your logic in the beginning like this)
Private Function DateRangeIsValid(ByVal dateRange As DateRangePicker) As Boolean
If IsNothing(dateRange.Select
Return True ' Both are Nothing
ElseIf IsNothing(dateRange.Select
Return False ' Only one is Nothing
End If
If dateRange.SelectedEndDate.
dateRange.SelectedEndDate.
End If
Return dateRange.SelectedEndDate.
End Function
ASKER
Thanks to both of you IDLE_MIND and ASPSQLSERVERCOM. I will check this and get back to you asap
ASKER
'dateRange.SelectedEndDate .Value = dateRange.SelectedEndDate. Value.AddD ays(1) ' It says expression is a value and therefore can't be the target of an assignment
Can you do it this way?
If dateRange.SelectedEndDate. Value.Date = dateRange.SelectedBeginDat e.Value.Da te Then
Dim dt As Date = dateRange.SelectedEndDate. Value.AddD ays(1)
dateRange.SelectedEndDate. Value = New Date(dt.Year, dt.Month, dt.Day)
End If
If dateRange.SelectedEndDate.
Dim dt As Date = dateRange.SelectedEndDate.
dateRange.SelectedEndDate.
End If
use
Dim dtDate As Date
dtDate = DateTime.Parse(stDate, Globalization.CultureInfo. CreateSpec ificCultur e("en-CA") )
dtDate = dtDate.AddDays(1)
Dim dtDate As Date
dtDate = DateTime.Parse(stDate, Globalization.CultureInfo.
dtDate = dtDate.AddDays(1)
ASKER
Idle MInd its showing up the same error
.....says expression is a value and therefore can't be the target of an assignment
.....says expression is a value and therefore can't be the target of an assignment
I'm not sure how to fix it then sorry...
ASKER
Should i write something on the btn_submit event ...what would you suggest?????
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
If Page.IsValid Then
Dim urlString As String = ""
Select Case Me.ddlReports.SelectedValue
Case "abc.aspx"
urlString = String.Format("abc.aspx?dteBegin={0}&dteEnd={1}", Me.drpReportDates.SelectedBeginDate.Value.ToShortDateString, Me.drpReportDates.SelectedEndDate.Value.ToShortDateString)
Case "bcd.aspx"
urlString = String.Format("bcd.aspx?dteBegin={0}&dteEnd={1}", Me.drpReportDates.SelectedBeginDate.Value.ToShortDateString, Me.drpReportDates.SelectedEndDate.Value.ToShortDateString)
End Select
Dim scriptString As New StringBuilder
scriptString.Append("<script language=JavaScript>")
scriptString.Append("window.open('" + urlString + "')")
scriptString.Append("</script>")
If (Not ClientScript.IsStartupScriptRegistered("Startup")) Then
ClientScript.RegisterStartupScript(GetType(Page), "Startup", scriptString.ToString)
End If
End If
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
.....says expression is a value and therefore can't be the target of an assignment.
Now if you are looking for an exact logic, please refer to my comment on ID:22653992 for codes. Here is the issue, if the selected case is abc.aspx, i don't have to add any date and it works fine with date params as 10/07/2008 to 10/07/2008. But if the selected case is bcd.aspx, the report errors out stating "Failed to retrieve data from the database. Error in File C:\WINDOWS\TEMP\{864593B4- 3C48-485A- 8E24-B40C9 BEDE6AE}.r pt".
Right now What i did on the statement: "Return dateRange.SelectedEndDate. Value.Date >= dateRange.SelectedBeginDat e.Value.Da te" removed "=" (without the quotes) from the statement and it works fine. But it doesn't allow user to choose/validate the same day on DateRangePicker, which again is kinda workaround :). But the requirement suggests that we need to be able to pass same date on the DateRangePicker. Any ideas....
Now if you are looking for an exact logic, please refer to my comment on ID:22653992 for codes. Here is the issue, if the selected case is abc.aspx, i don't have to add any date and it works fine with date params as 10/07/2008 to 10/07/2008. But if the selected case is bcd.aspx, the report errors out stating "Failed to retrieve data from the database. Error in File C:\WINDOWS\TEMP\{864593B4-
Right now What i did on the statement: "Return dateRange.SelectedEndDate.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks All