Omesh Omesh - 4 months ago 8
ASP.NET (C#) Question

How to display a string value in a Calendar control?

I have a string value which is in DateTime format where I have captured from a different Calendar control; How can I display that value in a Calendar control in a asp.net form?

string dateTo = dsDept.SelectedRow.Cells[3].Text;
string datefrom = dsDept.SelectedRow.Cells[2].Text;


Two string values are selected from a data grid view. I need these two dates to be displayed in two Calendar controls.

Answer

You need to convert that to DateTime and then assign to calendar SelectedDate property like

  DateTime capturedDate;
  if(DateTime.TryParse(dateTo, out capturedDate))
    {
       Calendar1.SelectedDate = capturedDate;
    }