Problem in populating the sqldatasource to raddatepicker

1 posts, 0 answers
  1. G
    G avatar
    4 posts
    Member since:
    May 2012

    Posted 18 Aug 2012 Link to this post

    I have the following code with the radComboxBox text value as the param to the sqldatasource. the result set of the sqldatasource will be populate to the raddatePick. this is not work. can anyone help me?

    -----------------------------------------aspx ------------------------------------------

    <%@ Page Language="c#" Inherits="imatrader_general_Default" CodeFile="Default.aspx.cs" %>


    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <%@ Register Src="../../Common/Header.ascx" TagName="Header" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div style="position: relative; top: 3px; left: 3px; width: 400px; height: 30px;">
            <telerik:Header runat="server" ID="Header1" NavigationLanguage="CS" ShowDbResetTimer="true">
            </telerik:Header>
        </div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">
                </asp:ScriptReference>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">
                </asp:ScriptReference>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">
                </asp:ScriptReference>
            </Scripts>
        </telerik:RadScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        </telerik:RadAjaxManager>
        <div style="position: relative; top: 10px; left: 3px; height: 30px; font: bold 20px Arial;">
            <asp:Label ID="Label1" runat="server" Text="Download" Height="27px"></asp:Label>
        </div>
        <div style="position: relative; top: 10px; left: 3px; height: 200px;">
            Symbol
            <telerik:RadComboBox ID="RadComboBox1" runat="server" AllowCustomText="true" Width='100'
                DataSourceID="SqlDataSource1" Filter="Contains" DataTextField="code" AutoPostBack="true " OnSelectedIndexChanged="RadComboBox1_OnSelectedIndexChanged">
            </telerik:RadComboBox>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MarketDbConnectionString %>"
                SelectCommand="SELECT '^HSCE' AS code UNION SELECT '^HSI' AS code UNION SELECT '^DJI' AS code UNION SELECT DISTINCT code FROM Quote ORDER BY Code">
            </asp:SqlDataSource>
            <br />
            <br />
            From
            <telerik:RadDatePicker ID="FromDatePicker" Width="100px" runat="server" SelectedDate='<%# Bind("startDate") %>'
                Culture="zh-HK">
                <DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton>
            </telerik:RadDatePicker>
            <%--        <telerik:RadDatePicker ID="RadDatePicker1" Width="100" runat="server" DbSelectedDate='<%# startDate %>'
                Culture="zh-HK" AutoPostBack="True" OnSelectedDateChanged="FromDatePicker_SelectedDateChanged">
                <Calendar ID="Calendar1" UseRowHeadersAsSelectors="False" runat="server" UseColumnHeadersAsSelectors="False"
                    ViewSelectorText="x">
                </Calendar>
                <DateInput ID="DateInput1" DisplayDateFormat="d/M/yyyy" DateFormat="d/M/yyyy" runat="server" LabelWidth="40%"
                    AutoPostBack="True">
                </DateInput>
                <DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton>
            </telerik:RadDatePicker>
            --%>
            &nbsp;To
            <telerik:RadDatePicker ID="ToDatePicker" Width="100" runat="server" DbSelectedDate='<%# endDate %>'
                Culture="zh-HK">
                <DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton>
            </telerik:RadDatePicker>
            <br />
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                ConnectionString="<%$ ConnectionStrings:MarketDbConnectionString %>" 
                SelectCommand="SELECT DATEADD(day, 1, MAX(tradeDate)) AS startDate FROM vwMaster WHERE (code = @code)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="RadComboBox1" Name="code" 
                        PropertyName="SelectedValue" />
                </SelectParameters>
            </asp:SqlDataSource>
            <br />
            <telerik:RadButton ID="RadButtonStart" runat="server" Text="Start" OnClick="RadButtonStart_Click">
            </telerik:RadButton>
            <br />
            <br />
            <asp:Label ID="lblResults" runat="server" Text=""></asp:Label>
            <br />
        </div>
        </form>
    </body>
    </html>


    ---------------------- cs ----------------------------

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;


    using System.Data;
    using System.Net;
    using System.Data.SqlClient;
    using YahooStocks;
    using Telerik.Web.UI.Skins;
    using Telerik.Web.UI;


    public partial class imatrader_general_Default : System.Web.UI.Page
    {


        protected DateTime? startDate
        {
            set
            {
                ViewState["strD"] = value;
            }
            get
            {
                if (ViewState["strD"] != null)
                    return (DateTime)ViewState["strD"];
                else
                    return new DateTime(DateTime.Today.Year - 1, DateTime.Today.Month, DateTime.Today.Day);
            }
        }
        protected DateTime? endDate
        {
            set
            {
                ViewState["endD"] = value;
            }
            get
            {
                if (ViewState["endD"] != null)
                    return (DateTime)ViewState["endD"];
                else
                    return DateTime.Today;
            }
        }
        protected void RadButtonStart_Click(object sender, EventArgs e)
        {


            YahooDownloader ydl = new YahooDownloader();
            DataTable dtable = ydl.UpdateSymbol(this.RadComboBox1.Text, FromDatePicker.SelectedDate, ToDatePicker.SelectedDate);
            //DataTable dtable = ydl.UpdateSymbol(this.RadComboBox1.Text, startDate, endDate);
            if (dtable != null)
            {
                string code = RadComboBox1.Text;
                ydl.InsertOrUpdateIssue(dtable, code);
            }
            lblResults.Text = ydl.getMessage();
        }
        //protected void FromDatePicker_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
        //{
        //    startDate = this.FromDatePicker.SelectedDate;
        //}


        //protected void ToDatePicker_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
        //{
        //    endDate = this.ToDatePicker.SelectedDate;
        //} 




        protected void RadComboBox1_OnSelectedIndexChanged(Object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
        }


        
        
        protected void Page_Load(object sender, EventArgs e)
        {
            //FromDatePicker.SelectedDate = startDate;
            //ToDatePicker.SelectedDate = endDate;
        }
        
    }
Back to Top