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

Setting the SelectedDate on a RadDatePicker

2 Answers 516 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Kieran Southern
Top achievements
Rank 1
Kieran Southern asked on 30 Oct 2008, 11:13 AM
Hi,

I'm setting the SelectedDate on a RadDatePicker like this:

SelectedDate='<%# Bind("TransactionDate") %>'

but I want to have it select todays date if the there is no TransactionDate, can anyone suggest how to do this?

Many Thanks

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Oct 2008, 02:19 PM
Hi,

Try the following code  snippet to achieve the desired scenario.

CS:
 
if (RadDatePicker1.SelectedDate == null) 
 { 
    RadDatePicker1.SelectedDate = DateTime.Today; 
            
  } 






Thanks
Shinu.
0
Daniel
Telerik team
answered on 31 Oct 2008, 09:50 AM
Hello Kieran,

I suppose your RadDatePicker is residing in RadGrid:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    GridDataItem item = e.Item as GridDataItem; 
    if (item != null
    { 
        if (DataBinder.Eval(item.DataItem, "MDate") == DBNull.Value) 
        { 
            if (item.IsInEditMode) 
                (item["MDate"].Controls[0] as RadDatePicker).SelectedDate = DateTime.Today; 
            else 
                item["MDate"].Text = DateTime.Today.ToString(); 
        } 
    } 

Let us know if your scenario differs from the suggested.

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Calendar
Asked by
Kieran Southern
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Daniel
Telerik team
Share this question
or