Home All Groups Group Topic Archive Search About

Calendar control in a datagrid returns wrong date

Author
31 Mar 2006 6:51 PM
Jon Prisbe
I have a datagrid. When the user presses "edit" I display a calendar control
in the 2nd cell. The cell's edit template is the calendar control.
The user selectes a date on the calendar and then presses "update".

Problem: the calendar always returns 1/1/01 when I call SelectedDate.

Here is my grid update code:
System.Web.UI.WebControls.Calendar cal = null;
cal = (System.Web.UI.WebControls.Calendar)e.Item.FindControl("Calendar1");
string date = cal.SelectedDate.ToShortDateString();

What am I doing wrong?

Thanks,

Author
31 Mar 2006 8:33 PM
Phillip Williams
//don't miss this check if you are databinding in Page_Load
if (!Page.IsPostBack ) 
    datagrid1.DataBind();
Show quoteHide quote
"Jon Prisbe" wrote:

> I have a datagrid. When the user presses "edit" I display a calendar control
> in the 2nd cell. The cell's edit template is the calendar control.
> The user selectes a date on the calendar and then presses "update".
>
> Problem: the calendar always returns 1/1/01 when I call SelectedDate.
>
> Here is my grid update code:
> System.Web.UI.WebControls.Calendar cal = null;
> cal = (System.Web.UI.WebControls.Calendar)e.Item.FindControl("Calendar1");
> string date = cal.SelectedDate.ToShortDateString();
>
> What am I doing wrong?
>
> Thanks,
Author
3 Apr 2006 11:01 AM
Jon Prisbe
Thanks Phillip.

That was my problem.



Show quoteHide quote
"Phillip Williams" wrote:

> //don't miss this check if you are databinding in Page_Load
> if (!Page.IsPostBack ) 
>     datagrid1.DataBind();
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "Jon Prisbe" wrote:
>
> > I have a datagrid. When the user presses "edit" I display a calendar control
> > in the 2nd cell. The cell's edit template is the calendar control.
> > The user selectes a date on the calendar and then presses "update".
> >
> > Problem: the calendar always returns 1/1/01 when I call SelectedDate.
> >
> > Here is my grid update code:
> > System.Web.UI.WebControls.Calendar cal = null;
> > cal = (System.Web.UI.WebControls.Calendar)e.Item.FindControl("Calendar1");
> > string date = cal.SelectedDate.ToShortDateString();
> >
> > What am I doing wrong?
> >
> > Thanks,