set asp parameter of sql data source to date picker.

6 posts, 1 answers
  1. Katya
    Katya avatar
    21 posts
    Member since:
    May 2013

    Posted 12 Nov 2013 Link to this post

    How to set the selected date of raddatepicker to asp parameter of an sql data source?
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 Nov 2013 Link to this post

    Hi Katya,

    For such scenarios I recommend using ASP ControlParameter so that you can directly specify the property name in the mark-up. Please check the following sample.

    ASPX:
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="select OrderID from [Orders] where OrderDate<@Date">
        <SelectParameters>
            <asp:ControlParameter ControlID="RadDatePicker1" Name="Date" PropertyName="SelectedDate"
                Type="DateTime" />
        </SelectParameters>
    </asp:SqlDataSource>

    If you want to use ASP Parameter, then you can try the following C# code in the Page_Load event.

    C#:
    SqlDataSource1.SelectParameters["Date"].DefaultValue = RadDatePicker1.SelectedDate.ToString();

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Katya
    Katya avatar
    21 posts
    Member since:
    May 2013

    Posted 12 Nov 2013 Link to this post

    Hi Shinu,

    Thanks for pointing me in the right direction.

    Can you please show how to add the same control parameter from the CS page?

    Thanks
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Nov 2013 Link to this post

    Hi Katya,

    Please check the sample code I have prepared for your scenario.

    ASPX:
    <telerik:RadDatePicker ID="RadDatePicker1" runat="server" AutoPostBack="true"
        onselecteddatechanged="RadDatePicker1_SelectedDateChanged">
    </telerik:RadDatePicker>
    <br />
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true" DataSourceID="SqlDataSource1">
    </telerik:RadGrid>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="select OrderID, CustomerID, ShipCity from [Orders] where OrderDate<@Date">
    </asp:SqlDataSource>

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ControlParameter parameter1 = new ControlParameter("Date", "RadDatePicker1", "SelectedDate");
            SqlDataSource1.SelectParameters.Add(parameter1);
        }
    }
    protected void RadDatePicker1_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
    {
        RadGrid1.Rebind();
    }

    Thanks,
    Shinu.
  6. Don
    Don avatar
    1 posts
    Member since:
    Jan 2015

    Posted 24 Jan 2015 Link to this post

    I recently migrated access db to sql 'backend data file' frontend access. I wanted to use date picker for all dates during data entry. I haven't been able to find the proc in sql after migrating. In access it's very simple 'leave off the xx/xx/xxxx prompt input'. I saw you examples but unable to relate to my request.
    Thanks,
    Don
  7. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 28 Jan 2015 Link to this post

    Hi Don,

    I am afraid I am not completely understand your requirement. Could you please provide more details to point you out in the right direction?

    Regards,
    Kostadin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017