1,105,214 Community Members

Display selected date from calendar into textbox

Member Avatar
maria_mj
Light Poster
41 posts since Mar 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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?

Member Avatar
kad1r
Newbie Poster
19 posts since Jun 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Try this:
Convert.ToString(myDate);

Member Avatar
hirenpatel53
Posting Whiz in Training
245 posts since Jun 2010
Reputation Points: -1 [?]
Q&As Helped to Solve: 31 [?]
Skill Endorsements: 0 [?]
 
0
 

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"); 
    }
}
Question Answered as of 3 Years Ago by hirenpatel53 and kad1r
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article