How to set date text as empty?

4 posts, 0 answers
  1. Paul
    Paul avatar
    19 posts
    Member since:
    Jul 2007

    Posted 12 Mar 2009 Link to this post

    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?
  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 16 Mar 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Paul
    Paul avatar
    19 posts
    Member since:
    Jul 2007

    Posted 16 Mar 2009 Link to this post

    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);  
                     }  
                }    
            }  
        } 
  5. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 17 Mar 2009 Link to this post

    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.
Back to Top