This is a migrated thread and some comments may be shown as answers.

How to set date text as empty?

3 Answers 428 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 12 Mar 2009, 02:37 PM
I'm using the templates of a gridview. In item template I use a label to show empty data if the date is a minimum sqldatetime (1/1/1753). In the edit template I use raddatepicker which reads the date as 1/1/1753 and displays it both in the textbox and the datepicker calendar. If the date is 1/1/53 I would like the textbox to appear blank and the datepicker to show todays date. Is this possible?

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 16 Mar 2009, 12:18 PM
Hi Paul,

Thank you for contacting us and for your question.

In order to achieve the scenario described by you, you have to wire up and event handler to the RowDataBound event of the grid view and add the following code to it:

        if (e.Row.RowState == DataControlRowState.Edit)  
        {  
            RadDatePicker datePicker = e.Row.FindControl("MyDatePicker"as RadDatePicker;  
 
            DateTime selectedDate = datePicker.SelectedDate.Value;  
            if(/*your condition for the data bound date value)*/)  
            {            
              
                datePicker.Clear();  
            
 
                RadCalendarDay day = new RadCalendarDay();  
 
                day.Repeatable = Telerik.Web.UI.Calendar.RecurringEvents.Today;  
               
                day.ItemStyle.CssClass = "rcToday";              
 
                datePicker.Calendar.SpecialDays.Add(day);  
             }  
              
             
        } 

Please, give it a try and let me know if I can help you further.

Best regards,
Tsvetoslav
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Paul
Top achievements
Rank 1
answered on 16 Mar 2009, 03:43 PM
Hi,

With a couple of tweaks to your code (alternate rows and if the date value was null) I managed to get this working which is great (see code below)

Please can you give me an idea how to do this in details view. When I click the edit button I'm using the ItemCommand but can't seem to find the rad control. I've tried itembound and prerender.

protected void Contacts_RowDataBound(object sender, GridViewRowEventArgs e)  
    {  
        if (e.Row.RowState == (DataControlRowState.Edit|DataControlRowState.Alternate)||e.Row.RowState == DataControlRowState.Edit)    
        {  
            RadDatePicker datePicker = e.Row.FindControl("radDateEditLastTrained"as RadDatePicker;  
 
            if (datePicker.SelectedDate.HasValue)  
            {  
                DateTime selectedDate = datePicker.SelectedDate.Value;  
                if (selectedDate.Date == (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue)  
                {   
                    datePicker.Clear();    
 
                    RadCalendarDay day = new RadCalendarDay();    
 
                    day.Repeatable = Telerik.Web.UI.Calendar.RecurringEvents.Today;   
 
                    datePicker.Calendar.SpecialDays.Add(day);  
                 }  
            }    
        }  
    } 
0
Tsvetoslav
Telerik team
answered on 17 Mar 2009, 11:45 AM
Hello Paul,

Try using the DataBound event of the DetailsView control. You can find the RadDatePicker directly through the DetailsView object itself:

    protected void DetailsView1_DataBound(object sender, EventArgs e)  
    {  
        RadDatePicker datePicker = DetailsView1.FindControl("dtpHireDate"as RadDatePicker;  
 
        if (datePicker != null)  
        {  
            DateTime selectedDate = datePicker.SelectedDate.Value;  
 
            datePicker.Clear();  
 
 
            RadCalendarDay day = new RadCalendarDay();  
 
            day.Repeatable = Telerik.Web.UI.Calendar.RecurringEvents.Today;  
 
 
 
            day.ItemStyle.CssClass = "rcToday";  
 
 
            datePicker.Calendar.SpecialDays.Add(day);  
        }  
      
    } 

Hope this helps.

All the best,
Tsvetoslav
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Calendar
Asked by
Paul
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Paul
Top achievements
Rank 1
Share this question
or