DateTime in dropdown

Discussion in 'ASP .Net' started by =?Utf-8?B?Q1NoYXJwZ3V5?=, Apr 13, 2006.

  1. I'm trying to populate a drop down with dates from a data field in my data
    base but I want the format like MM/dd/yyyy instead of 1/1/2006 12:00 PM
    How can I my date to show as 1/1/2006?

    I'm populating the dropdown via a dataset and doing a:
    string time =
    Convert.ToDateTime(dataset.tables[0].rows[0]["fieldDate"].toString()).ToShortDateString();
    dropdown.datatexfield = time;
    dropdown.datavaluefield = time
    dropdown.databind();

    DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with
    the name 12/31/2006

    and it highlights this code:
    dropdown.databind();

    what am I missing?

    but i'm getting this error:
    =?Utf-8?B?Q1NoYXJwZ3V5?=, Apr 13, 2006
    #1
    1. Advertising

  2. What is the DataSource for the dropdownlist ?

    --
    Swanand Mokashi
    Microsoft Certified Solution Developer (.NET) - Early Achiever
    Microsoft Certified Application Developer (.NET)

    http://www.dotnetgenerics.com/
    DotNetGenerics.com -- anything and everything about Microsoft .NET
    technology ...

    http://www.swanandmokashi.com/
    http://www.swanandmokashi.com/HomePage/WebServices/
    Home of the Stock Quotes, Quote of the day and Horoscope web services


    "CSharpguy" <> wrote in message
    news:...
    > I'm trying to populate a drop down with dates from a data field in my data
    > base but I want the format like MM/dd/yyyy instead of 1/1/2006 12:00 PM
    > How can I my date to show as 1/1/2006?
    >
    > I'm populating the dropdown via a dataset and doing a:
    > string time =
    > Convert.ToDateTime(dataset.tables[0].rows[0]["fieldDate"].toString()).ToShortDateString();
    > dropdown.datatexfield = time;
    > dropdown.datavaluefield = time
    > dropdown.databind();
    >
    > DataBinder.Eval: 'System.Data.DataRowView' does not contain a property
    > with
    > the name 12/31/2006
    >
    > and it highlights this code:
    > dropdown.databind();
    >
    > what am I missing?
    >
    > but i'm getting this error:
    >
    >
    Swanand Mokashi, Apr 13, 2006
    #2
    1. Advertising

  3. dropdown.datasource = dataset;
    should it be different?
    even doing this is returning me the dateTime as 1/1/006 12:00 PM

    DataSet startDate= SalesForYear.GetStartingDates();
    dropDown.DataSource = asOfDate.Tables[0].DefaultView;
    dropDown.DataTextField = String.Format("{0:d}", "fieldDate");
    ddMonthEnd.DataValueField = String.Format("{0:d}", "fieldDate");
    dropDown.DataBind();


    "Swanand Mokashi" wrote:

    > What is the DataSource for the dropdownlist ?
    >
    > --
    > Swanand Mokashi
    > Microsoft Certified Solution Developer (.NET) - Early Achiever
    > Microsoft Certified Application Developer (.NET)
    >
    > http://www.dotnetgenerics.com/
    > DotNetGenerics.com -- anything and everything about Microsoft .NET
    > technology ...
    >
    > http://www.swanandmokashi.com/
    > http://www.swanandmokashi.com/HomePage/WebServices/
    > Home of the Stock Quotes, Quote of the day and Horoscope web services
    >
    >
    > "CSharpguy" <> wrote in message
    > news:...
    > > I'm trying to populate a drop down with dates from a data field in my data
    > > base but I want the format like MM/dd/yyyy instead of 1/1/2006 12:00 PM
    > > How can I my date to show as 1/1/2006?
    > >
    > > I'm populating the dropdown via a dataset and doing a:
    > > string time =
    > > Convert.ToDateTime(dataset.tables[0].rows[0]["fieldDate"].toString()).ToShortDateString();
    > > dropdown.datatexfield = time;
    > > dropdown.datavaluefield = time
    > > dropdown.databind();
    > >
    > > DataBinder.Eval: 'System.Data.DataRowView' does not contain a property
    > > with
    > > the name 12/31/2006
    > >
    > > and it highlights this code:
    > > dropdown.databind();
    > >
    > > what am I missing?
    > >
    > > but i'm getting this error:
    > >
    > >

    >
    >
    >
    =?Utf-8?B?Q1NoYXJwZ3V5?=, Apr 13, 2006
    #3
  4. You can not use the formatting function when specifying teh DataTextField or
    DataValueField. What is happening is if the date is 1/1/006 12:00 PM, the
    DataTextField is "1/1/2006" -- there is no such field in your dataset. Hence
    the error.

    You can either format the date when you are getting the data (as in
    SalesForYear.GetStartingDates method) or use the DataBinding event of the
    dropdownlist.


    --
    Swanand Mokashi
    Microsoft Certified Solution Developer (.NET) - Early Achiever
    Microsoft Certified Application Developer (.NET)

    http://www.dotnetgenerics.com/
    DotNetGenerics.com -- anything and everything about Microsoft .NET
    technology ...

    http://www.swanandmokashi.com/
    http://www.swanandmokashi.com/HomePage/WebServices/
    Home of the Stock Quotes, Quote of the day and Horoscope web services



    "CSharpguy" <> wrote in message
    news:D...
    > dropdown.datasource = dataset;
    > should it be different?
    > even doing this is returning me the dateTime as 1/1/006 12:00 PM
    >
    > DataSet startDate= SalesForYear.GetStartingDates();
    > dropDown.DataSource = asOfDate.Tables[0].DefaultView;
    > dropDown.DataTextField = String.Format("{0:d}", "fieldDate");
    > ddMonthEnd.DataValueField = String.Format("{0:d}", "fieldDate");
    > dropDown.DataBind();
    >
    >
    > "Swanand Mokashi" wrote:
    >
    >> What is the DataSource for the dropdownlist ?
    >>
    >> --
    >> Swanand Mokashi
    >> Microsoft Certified Solution Developer (.NET) - Early Achiever
    >> Microsoft Certified Application Developer (.NET)
    >>
    >> http://www.dotnetgenerics.com/
    >> DotNetGenerics.com -- anything and everything about Microsoft .NET
    >> technology ...
    >>
    >> http://www.swanandmokashi.com/
    >> http://www.swanandmokashi.com/HomePage/WebServices/
    >> Home of the Stock Quotes, Quote of the day and Horoscope web services
    >>
    >>
    >> "CSharpguy" <> wrote in message
    >> news:...
    >> > I'm trying to populate a drop down with dates from a data field in my
    >> > data
    >> > base but I want the format like MM/dd/yyyy instead of 1/1/2006 12:00 PM
    >> > How can I my date to show as 1/1/2006?
    >> >
    >> > I'm populating the dropdown via a dataset and doing a:
    >> > string time =
    >> > Convert.ToDateTime(dataset.tables[0].rows[0]["fieldDate"].toString()).ToShortDateString();
    >> > dropdown.datatexfield = time;
    >> > dropdown.datavaluefield = time
    >> > dropdown.databind();
    >> >
    >> > DataBinder.Eval: 'System.Data.DataRowView' does not contain a property
    >> > with
    >> > the name 12/31/2006
    >> >
    >> > and it highlights this code:
    >> > dropdown.databind();
    >> >
    >> > what am I missing?
    >> >
    >> > but i'm getting this error:
    >> >
    >> >

    >>
    >>
    >>
    Swanand Mokashi, Apr 13, 2006
    #4
    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. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    686
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    519
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    373
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    328
    Martin
    Dec 27, 2008
  5. Replies:
    2
    Views:
    743
    M.-A. Lemburg
    Jan 6, 2009
Loading...

Share This Page