.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Problem displaying Date from Sql table on Calendar Control

Posted By:      Posted Date: September 06, 2010    Points: 0   Category :ASP.Net
Hi, I am displaying Event dates from SQL table on Calendar Control in ASP.NET. Also, I have GridView Control which shows event details when certain date is clicked on calendar control. But I have a problem as not all dates are displaying properly. Strangly enough only dates which have same month and day date are displayed. For example: It shows ok dates such as 08/08/2010, 09/09/2010, 10/10/2010 etc. If I click on the date which in SQL table exists as 11/25/2010 or 12/15/2010 etc (no matching month/day numbers) it shows error message saying: "System.Data.SqlClient.SqlException: Conversion failed when converting date and/or time from character string."  Follwoing is my code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.Sql; using System.Runtime.Remoting.Messaging; using System.Configuration; using System.Data.SqlClient; using System.Data; using System.Drawing; public partial class Test_Calendar : System.Web.UI.Page { SqlConnection mycn; SqlDataAdapter myda; DataSet ds = new DataSet(); DataSet dsSelDate; String strConn; private void Page_Load(object sender, System.EventArgs e) { strConn = "Data Source=mydatasource;Initial Catalog=DBname;Persist Security I

View Complete Post

More Related Resource Links

Calendar control and date


I have a calendar control , text box and a button . The calendar is invisible in the page load event. When I click on the button,It becomes visible. On selection of a date it becomes the value of the Text Box.
Having said that, my issue is that when this calendar becomes visible, it ruins the arrrangement of the controls on the  page. As I have other controls on the page they  comepletely get displaced. Is there a way to overlap this calendar over the other controls.
I had seen a control that was  some time ago and it was on the client side(probably using javascript or a third party control ) and It wud overlap the other controls and once a value was selected it became invisible.

How to change the date format using AJAX calendar control tookit


I want to desplay date like (21-Sep-2010)

Small problem with displaying custom calendar cell text from db in Safari


using VS2010

I'm using the calendar control to create a simple event calendar. I want to add a small bit of custom text just below the date of any cell that contains an event on that date.

The code:

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
      string connString = ConfigurationManager.ConnectionStrings["CalendarConnectionString1"].ToString();
      SqlConnection myConnection = new SqlConnection(connString);
      SqlDataAdapter myAdapter = new SqlDataAdapter("GetEvents", myConnection);
      DataSet myDataSet = new DataSet();
      myAdapter.Fill(myDataSet, "Table");
      //If the month is CurrentMonth
      if (!e.Day.IsOtherMonth)
        foreach (DataRow dr in myDataSet.Tables[0].Rows)
          if ((dr["Date"].ToString() != DBNull.Value.ToString()))
            DateTime dtEvent = (DateTime)dr["Date"];
            if (dtEvent.Equals(e.Day.Date))
              e.Cell.BackColor = Color.MediumAquamarine;
              Label label = new Label();
              label.Text = "</br>";
              label.Text += dr["Title"].ToString();              

Problem inserting a null value into date column in SQL table


Hi all,

I am having a hard time inserting a null date into a SQL table.  Please be aware that I am using the Microsoft Application Data Blocks and not pure ADO.net.  I find a million examples of how to do this with ADO.net but cannot find anything about this using the MS Data Application Blocks.

Here is my VB.net code:

Save(Session("ref_no"),  txtdischarge_date.Text) 

Sub Save(ByVal ref_no As Integer, discharge_date As Date)

        SqlHelper.ExecuteNonQuery(connString, ref_no, discharge_date), "MyTableInsert")

End Sub

The textbox txtdischarge_date can either be a valid date or blank.  If it contains a valid date then the insert works properly.  But if the textbox  is blank, then I want to insert a null value into my date column.  I cannot get this to work.  I get this error when I run this and txtdischarge_date is blank:

Conversion from string "" to type 'Date' is not valid

Here is the code for my stored procedure, MyTableInsert:

ALTER Procedure MyTableInsert
   (@ref_no int,
    @discharge_date datetime = NULL)

Get selected date value from DropDownList control and pass it to SQL table



This must be something not very difficult but I am pretty new in C# and have a problem to resolve.

I have tree dropdownlist controls. One of the control values are dates. When client selects all three drop downs then I am passing values to SQL table. Everything works but one. Date value shows 1900-01-01 instead of selected value in SQL table. I am not passing date value correctly but can't figure out how to do it.

Following is a code:

                            <asp:DropDownList ID="ddlLocation" runat="server" AutoPostBack="True" 
                                DataSourceID="SqlDataSource3" DataTextField="ShowLocation" 
                            <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:myconnection%>" 
                                SelectCommand="SELECT * FROM [ShowLocation]"></asp:SqlDataSource>

Problem in setting calendar selected date


I am using the fallowing code to set the selected date of calendar control to one day previous of the current date, but still the calendar is showing the current date as the selected date.

Calendar1.SelectedDate =


can anyone help me regarding this issue.

How To Add calendar control inside a GridView

This article show hot to add calendar control inside a GridView with code in c#

Using ATLAS PopUp Control with Calendar inside the GridView Control

In this video tutorial Mohammad demonstrates how you can access the Calendar control which is displayed using the ATLAS PopUp control inside the GridView control.

Reuse a gridview within calendar control


Hello, I have a calendar control that will have events displayed within each cell.

I want to use a pre formatted gridview and simply bind the gridview with a dataset dynamically and display it within the cell of the specified day.

Is there a way to do that or do I have to dynamically build a gridview for every day that there is an event? 

So here is the template gridview and datasource:

 <asp:SqlDataSource ID="sqlcalitemtemp" runat="server" 
        ConnectionString="<%$ ConnectionStrings:NNTrainingdbconnection %>" 
        SelectCommand="SELECT NN_Fire_Events.Start_Time, NN_Fire_Events.End_Time, tblNN_Fire_Cli

Problem getting applicaton to run after retrieving it from source control software.


I am restoring my asp 2.0 app from a source control project to my local drive.

The application was originally created on a different PC but was created with Visual Studio 2005,

ASP.net 2.0.

The source control add-in (Harvest) is not working correctly so I retrieving and saving my web app

outside of Visual Studio.

I finally put all the pieces of the web app back together but now when I compile my app I get the following message:

Build (web): Could not load the assembly 'App_Web_myApplication.master.cdcab7d2'. Make sure that it is compiled before accessing the page.

Will I have to start over ?

Thanks for your insights !

Problem when displaying a popup window

Hi all,
I am working on a project in which when I clicked a hyperlink a pop up window has to be displayed for 2 pages.
But at first when i did this in javascript it worked, later after i finished the whole coding suddenly an error box displayed that there is an error in webpage and want to debug

change calendar date backColor base on data from db


I want to  change calendar date backColor base on data from db,  I only have vistual 2003 !

on mean time I have

<asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 23px; POSITION: absolute; TOP: 271px"
		    runat="server" Font-Size="XX-Small" Font-Names="Verdana" AutoGenerateColumns="False" Visible="False">
           <asp:BoundColumn DataField="subject" HeaderText="Title"></asp:BoundColumn>
           <asp:BoundColumn DataField="posttimestart" HeaderText="Post date"></asp:BoundColumn>


Sub DayRender(ByVal source As Object, ByVal e As DayRenderEventArgs)
        Dim i As Integer
        For i = 0 To DataGrid1.Items.Count - 1
            If (DataGrid1.Items(i).Cells(1).Text = e.Day.Date) Then
                e.Cell.BackColor = Color.DarkOrange

            End If

    End Sub

when I click the day wich have data in db it change  color , but I want the page load it change color !

Thank you!

Stored Procedures & SqlDataAdapter not updating a calendar control


Hi all,

I have a database linked to a calendar. I had a peice of code that retrieved dates from a database and populated the calendar. I wanted to tidy up my code using stored procedures (they seem neater & i assume there's a benefit somewhere). so i came up with this, however it's not working. The calendar displays, but it's not being populated with the database entries. The SqlCommand & SqlParameter I have working elsewhere in my code; as with the SqlDataAdapter (which also worked before i tried to conver to a stored procedure!) but combining these three (SqlCommand, SqlParameter & SqlDataAdapter) seem to be causing me problems.

It's probably something stupid but if someone could take a look and point me in the right direction, I'd be very grateful.


Public Sub dbConnection()
        dbConnString = ConfigurationManager.ConnectionStrings("connString").ConnectionString
        sqlConn = New SqlConnection(dbConnString)
    End Sub

Public Sub EquipmentDDLSelection()

        Dim dbCMD As New SqlCommand("PopulateCalendar", sqlConn)
        dbCMD.CommandType = CommandType.StoredProcedure

        Dim parameterBookedEvents As New SqlParameter("@bookedEvents", SqlDbType.VarChar, 50)

calendar control, show onHover


hi all,
is it possible to have a calendar control on an asp.net page that is diplayed only onHover over some area?
Most of the times, the control won't be needed and I would like to save the space for something else. In case the calendar is needed I want it to slide down from under a link or button (most likely it will be an image there).

thanks a bunch,

Submtting Calendar items with variable date information via InfoPath 2007 form



I've seen several posts regarding submitting to a list using and InfoPath form which I am successfully able to do in limited form. (only passing a basic date value) My environment: MOSS 2007 Enterprise w/SP2, InfoPath 2007, SPD 2007.

I'm basically trying to recreate a calendar form with the same data elements (and some additional ones for a specific business requirement) as the standard calendar newform.aspx form. (start time, end time broken down by date, hour, minute and All day event)

I need the form users to be able to select the date and if it is not an All day event...be able to select the hours and minutes just like on the newform.aspx. (date picker control for date and drop downs for hour and minute selection)

On submit I then need to create the list item with the appropriate data passed via a workflow.

My Start Time has a validation rule to not allow dates prior to the current date (and it can't blank) The End Time has a validation rule to not allow dates prior to what is specified as the Start Time value. (Also can't be blank) When I attempt to include conditonal formatting to hide the hour and minute drop downs if 'All Day Event' is selected I get errors stating the fields can't be blank.

I also can't figure out how to pass the entire date/time values or the All Day Event to the list withou

Problem with Wizard Control



I have a wizard, which contains a series of custom user controls as steps. Also I am using the step navigation template to add in the navigation buttons.

However, due to some steps needing a little time to load fully due to web service calls and having to add some dynamic steps, I would like to disable the navigation buttons until the next step has been loaded and change the text on the "Next Button" to "loading...". Is there away I can do this perhaps with JavaScript or is there away I could do this with an AJAX control? If so, does anyone have an example I could use?


Jquery date picker in ASP.NET Web user control does not work


Hello, I have the most frustrating problem and being new to JQuery does make it more difficult. I have an ASP.NET web user control with an ASP.NET box which I want to apply a JQuery date picker to, then of course I have server side code which takes the date and processes it etc. The date picker will not work. I can achieve a working JQuery date picker with an ASP.NET textbox if there is no user control involved, or within the user control I use a html text box instead, but once I add runat="server" to the text box, it does not work. Is there a way I can achieve this? (the web user control will be wrapped in an update panel too which at the moment will work with the html control/web user control without the server side functionality)

<%@ Register TagPrefix="TE" TagName="JobHistory" Src="test.ascx"%>

<!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">


    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

    <link h

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend