Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using the calendar tool for asp.net

Posted on 2010-08-31
6
Medium Priority
?
629 Views
Last Modified: 2012-05-10
Hello, currently I using a dropdown box to hold dates to use the query information. I have a start date and a end date. I want to convert this to a calendar function but I'm getting the following errors:

System.web.ui.webcontrols.calendar does not contain a definition for "DataSource"
System.web.ui.webcontrols.calendar does not contain a definition for "DataValueField"
System.web.ui.webcontrols.calendar does not contain a definition for "DataTextField"

I'm still learning some of this .net stuff and I'm taking over for someone so I need a little help to fix this issue for production. Below is the code of the aspx.cs file. What do I need to change so that I can use the dates from database to collorate with the calendar. The format of the dates is 8/23/2010. Thanks!!
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

public partial class customerContractUsage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Roles.IsUserInRole("Admin") && !Roles.IsUserInRole("Poster") && !Roles.IsUserInRole("Customer")) Response.Redirect("default.aspx");

        Database dbMW = DatabaseFactory.CreateDatabase("MW_WebDataSource");
        Database dbRMS = DatabaseFactory.CreateDatabase("RMS_DataSource");

        //If the database is being updated display this message
        lblUpdating.Visible = ("Y" == "" + dbMW.ExecuteScalar(dbMW.GetSqlStringCommand("SELECT update_status FROM GLOBALSETTINGS")));

        if (!IsPostBack)
        {
            //Fill DDL Date Lists

            // ****** Is Technology  ******
            String sessBAID = Session["BAID"].ToString();
            DbCommand cmd = dbRMS.GetSqlStringCommand("Select Distinct(CONVERT(VARCHAR(7),ObligationFromDate,120)) Date, Replace(RIGHT(CONVERT(VARCHAR(11),ObligationFromDate,113), 8), ' ', '-') DisplayDate From RMS.rms_dbo.ra_OBLIGATIONS Where BAID = @sessBAID Order By CONVERT(VARCHAR(7),ObligationFromDate,120) Desc");
            dbRMS.AddInParameter(cmd, "@sessBAID", DbType.String, sessBAID);
            DataSet ds = dbRMS.ExecuteDataSet(cmd);
            //String ddlSQL = "Select Distinct(CONVERT(VARCHAR(7),ObligationFromDate,120)) Date, Replace(RIGHT(CONVERT(VARCHAR(11),ObligationFromDate,113), 8), ' ', '-') DisplayDate From RMS.rms_dbo.ra_OBLIGATIONS Where BAID = " + Session["BAID"] + " Order By CONVERT(VARCHAR(7),ObligationFromDate,120) Desc";
            //DataSet ds = dbRMS.ExecuteDataSet(dbRMS.GetSqlStringCommand(ddlSQL));
            // ****** Is Technology  ******

            ddlStartDate.DataSource = ds;
            ddlStartDate.DataValueField = "Date";
            ddlStartDate.DataTextField = "DisplayDate";
            ddlStartDate.DataBind();
            ddlEndDate.DataSource = ds;
            ddlEndDate.DataValueField = "Date";
            ddlEndDate.DataTextField = "DisplayDate";
            ddlEndDate.DataBind();
        }
        else
        {
            //We have a post back, read the data!
        }
    }
}

Open in new window

0
Comment
Question by:DancingFighterG
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:Seven price
ID: 33568788
Not understanding --
>>What do I need to  change so that I can use the dates from database to collorate with the  calendar. The format of the dates is 8/23/2010

do you want to set the format?
do you want to use todays date what ever today may be.

0
 

Author Comment

by:DancingFighterG
ID: 33568876
I want to use the calendar to selet dates instead of using a dropdown box that has dates populated in them from the databases.
0
 
LVL 9

Accepted Solution

by:
Seven price earned 2000 total points
ID: 33569218
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
foreach(DateTime dt in Calendar1.SelectedDates)
{
Response.Write(dt.ToString() +"<BR>");
}
}

<asp:Calendar ID="Calendar1" runat="server"  onselectionchanged="Calendar1_SelectionChanged"  SelectionMode="DayWeekMonth"></asp:Calendar>

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
foreach(DateTime dt in Calendar1.SelectedDates)
{
Response.Write(dt.ToString() +"<BR>");
}
}

http://www.w3schools.com/aspnet/control_calendar.asp

I am not sure I helped you on this. but above code should help you as a starting point.
0
 

Author Comment

by:DancingFighterG
ID: 33569319
The following lines is binding the values from the database to these ids:

ddlStartDate.DataSource = ds;
ddlStartDate.DataValueField = "Date";
ddlStartDate.DataTextField = "DisplayDate";
ddlStartDate.DataBind();
ddlEndDate.DataSource = ds;
ddlEndDate.DataValueField = "Date";
ddlEndDate.DataTextField = "DisplayDate";
ddlEndDate.DataBind();

Now from the error htat I am gettting:

System.web.ui.webcontrols.calendar does not contain a definition for "DataSource"
System.web.ui.webcontrols.calendar does not contain a definition for "DataValueField"
System.web.ui.webcontrols.calendar does not contain a definition for "DataTextField"

Are not compatiable with the calander function. Is that correct?
0
 

Author Comment

by:DancingFighterG
ID: 33569579
I was looking at the following page:

http://demo.mediachase.com/calendar.net/DataBinding/DataBinding.aspx

it states that the calendar supports the Datasource defintion but I'm still getting errors
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question