How to set raddatepicker date with database retrieved date

sidhewsar picture sidhewsar · Aug 3, 2013 · Viewed 8.8k times · Source

I want to set the RadDatePicker value to a value retrieved from my database

I have this code

DateTime Podate = Convert.ToDateTime(da.GetDataKeyValue("PoDt"));
RadDatePicker.SelectedDate =Podate;

but when I run this program the DatePicker shows blank value

What should I do? Please help

Answer

zey picture zey · Aug 3, 2013

Try likes this ,

  protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
     RadDatePicker.SelectedDate = 
     DateTime.Parse(da.GetDataKeyValue("PoDt").ToString());
        }
    }

If not working by this code , please check with

     RadDatePicker.SelectedDate = DateTime.Now;

If it work with this , you have to check your retrieve data da.GetDataKeyValue("PoDt") .
It may be in wrong datetime dataformat !