I have try to display selected date from calendar into textbox.
But, I got error.

My textbox name is txtStart
My calendar name is Calendar1


Here is my code..

protected void Calendar1_SelectionChanged(object sender, System.EventArgs e)  
{  
    System.DateTime myDate = new System.DateTime();  
    myDate = Calendar1.SelectedDate.ToString("MM/dd/yyyy");  
    txtStart.Text = myDate;  
}

The error is:
Cannot implicitly convert type 'string' to 'System.DateTime'
Cannot implicitly convert type 'System.DateTime' to 'string'

can someone help me about the error?

Recommended Answers

All 2 Replies

Try this:
Convert.ToString(myDate);

Use this code it working tested by me if working with ur application please marked as solved

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        System.DateTime myDate = new System.DateTime(); 
        myDate =  Calendar1.SelectedDate; 
         txtStart.Text = myDate.ToString ("dd/MM/yyyy"); 
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.