Solved

Using the calendar tool for asp.net

Posted on 2010-08-31
6
595 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:sevensnake77
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:
sevensnake77 earned 500 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now