Calendar control in a datagrid returns wrong date

Discussion in 'ASP .Net Web Controls' started by Jon Prisbe, Mar 31, 2006.

  1. Jon Prisbe

    Jon Prisbe Guest

    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,
    Jon Prisbe, Mar 31, 2006
    #1
    1. Advertising

  2. //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,
    Phillip Williams, Mar 31, 2006
    #2
    1. Advertising

  3. Jon Prisbe

    Jon Prisbe Guest

    Thanks Phillip.

    That was my problem.



    "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,
    Jon Prisbe, Apr 3, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shevek
    Replies:
    3
    Views:
    6,012
    Shevek
    Jun 23, 2004
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,229
    Michael Borgwardt
    May 30, 2004
  3. Shevek
    Replies:
    0
    Views:
    375
    Shevek
    Jun 23, 2004
  4. Jacob Gorban
    Replies:
    12
    Views:
    236
    Reid Thompson
    Nov 2, 2009
  5. David Woodward
    Replies:
    5
    Views:
    369
    Dr John Stockton
    Feb 2, 2004
Loading...

Share This Page