Click here to Skip to main content
14,126,835 members
Rate this:
Please Sign up or sign in to vote.
i entered a date range, but datepicker is taking default date(current date as assigned) when seraching a data.

What I have tried:

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
     If Not Me.IsPostBack Then
         PickerFrom.SelectedDate = Today
         PickerTo.SelectedDate = Today
     End If
 End Sub

 Private Sub Search()
     Dim strWhere As String = ""
     strWhere = "orderdate between '" & PickerFrom.SelectedDate.Value.ToString("MM/dd/yyyy") & "' and '" & PickerTo.SelectedDate.Value.AddDays(1).AddSeconds(-1).ToString("MM/dd/yyyy") & "' and OID=" & CStr(Filter.OrganisationId)
     Dim SqlCommand As New SqlCommand
     Dim connection As String = ConfigurationManager.ConnectionStrings("VService").ConnectionString
     Dim con As New SqlConnection(connection)
     SqlCommand.CommandText = "Custom_Analysers_PartSales_Freight"
     SqlCommand.Parameters.Add("@Type", SqlDbType.VarChar).Direction = ParameterDirection.Input
     SqlCommand.Parameters("@Type").Value = "Partsales"
     SqlCommand.Parameters.Add("@whereclause", SqlDbType.VarChar).Direction = ParameterDirection.Input
     SqlCommand.Parameters("@whereclause").Value = strWhere
     SqlCommand.CommandTimeout = 0
     SqlCommand.Connection = con
     SqlCommand.CommandType = CommandType.StoredProcedure
     Dim sqlDA As New SqlDataAdapter(SqlCommand)
     Dim ds As New DataSet
     Grid.DataSource = ds.Tables(0).DefaultView
 End Sub

 Protected Sub Grid_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles Grid.NeedDataSource
     If PickerFrom.SelectedDate.HasValue Then
     End If
 End Sub

 Protected Sub Grid_PageIndexChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridPageChangedEventArgs) Handles Grid.PageIndexChanged
     Grid.CurrentPageIndex = e.NewPageIndex
 End Sub

 Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
 End Sub

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="DotNetSmith.WebControls" Namespace="DotNetSmith.WebControls" TagPrefix="dns" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="ajax" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">   
      <dns:DotNetSmithUserMessageSummary ID="Umsg" runat="server" CssClass="MessageBlockError" />
   <table cellspacing="4" cellpadding="0" border="0" width="100%">
            <td align="right"><font color="red">All amounts are exclusive of tax</font></td>
   <fieldset id="fdsExceptionTracking" runat="server">
   <legend>Parts Sales Analyser</legend>   
            <table cellspacing="4" cellpadding="0" border="0">
                <td align="right" width="35%">Select Date Range:</td>
                    <telerik:RadDatePicker ID="PickerFrom" runat="server" Width="140px" DateInput-DateFormat="dd/MM/yyyy" SkinID="CustomRadDatePickerSkin"
                            DateInput-EmptyMessage="MinDate" MinDate="01/01/1000" MaxDate="01/01/3000">
                            <Calendar ID="Calendar1" runat="server">
                                    <telerik:RadCalendarDay Repeatable="Today" ItemStyle-CssClass="rcToday" />
                    <telerik:RadDatePicker ID="PickerTo" runat="server" Width="140px" DateInput-DateFormat="dd/MM/yyyy" SkinID="CustomRadDatePickerSkin"
                            DateInput-EmptyMessage="MaxDate" MinDate="01/01/1000" MaxDate="01/01/3000">
                            <Calendar ID="Calendar2" runat="server">
                                    <telerik:RadCalendarDay Repeatable="Today" ItemStyle-CssClass="rcToday"  />
                <td><asp:Button ID="btnSearch" runat="server" Text="Search" /></td>
Updated 5-Sep-18 9:19am
Richard Deeming 5-Sep-18 11:58am
strWhere = "orderdate between '" & PickerFrom.SelectedDate.Value.ToString("MM/dd/yyyy") & "' and '" & PickerTo.SelectedDate.Value.AddDays(1).AddSeconds(-1).ToString("MM/dd/yyyy") & "' and OID=" & CStr(Filter.OrganisationId)

Don't do it like that! Your code is almost certainly vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]

It seems your stored procedure is using dynamic SQL without parameterizing it. You need to use sp_executesql[^] with a properly parameterized query.
Manoj Jagdale 5-Sep-18 12:50pm
Ok Sir, but can above solution solve my problem of holding value in datepicker control.
Manoj Jagdale 6-Sep-18 7:38am
Can there is any another solution, please?
Vinod Jangle 6-Sep-18 8:41am
Did you checked if your control retains the value you assigned when "SEARCH" is called. You defaulted the value for date controls to Today on Pre-render.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190518.1 | Last Updated 5 Sep 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100