How to format "Drop Down List" TextFields and ValueFields?

Discussion in 'ASP .Net' started by =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=, Jul 4, 2005.

  1. Hello -

    I've binded a dataset to a Drop Down List control on my web form, using C#,
    however, the DateTime value is printed in long format. For example:
    04/07/2006 12:00 AM.

    My code is:

    ddlObs.DataSource = ds.Tables["Observations"].DefaultView;
    ddlObs.DataTextField = "ObsDate";
    ddlObs.DataValueField = "ObsDate";

    How can I use the ddlObs.DataTextFormatString property so that the TextField
    value is only "04/07/2005"?

    Thanks,
    =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=, Jul 4, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=

    Lars Netzel Guest

    Check the:
    DataTextFormatString() Property on DropDownLists

    /Lars

    "charliewest" <> wrote in message
    news:...
    > Hello -
    >
    > I've binded a dataset to a Drop Down List control on my web form, using
    > C#,
    > however, the DateTime value is printed in long format. For example:
    > 04/07/2006 12:00 AM.
    >
    > My code is:
    >
    > ddlObs.DataSource = ds.Tables["Observations"].DefaultView;
    > ddlObs.DataTextField = "ObsDate";
    > ddlObs.DataValueField = "ObsDate";
    >
    > How can I use the ddlObs.DataTextFormatString property so that the
    > TextField
    > value is only "04/07/2005"?
    >
    > Thanks,
    Lars Netzel, Jul 4, 2005
    #2
    1. Advertising

  3. Lars,

    this feedback is really *not* helpful, as the source you reference is quite
    obvious. I do read the manual before posting. if you would read the
    documentation yourself, the information only refers to numeric values.

    "Lars Netzel" wrote:

    > Check the:
    > DataTextFormatString() Property on DropDownLists
    >
    > /Lars
    >
    > "charliewest" <> wrote in message
    > news:...
    > > Hello -
    > >
    > > I've binded a dataset to a Drop Down List control on my web form, using
    > > C#,
    > > however, the DateTime value is printed in long format. For example:
    > > 04/07/2006 12:00 AM.
    > >
    > > My code is:
    > >
    > > ddlObs.DataSource = ds.Tables["Observations"].DefaultView;
    > > ddlObs.DataTextField = "ObsDate";
    > > ddlObs.DataValueField = "ObsDate";
    > >
    > > How can I use the ddlObs.DataTextFormatString property so that the
    > > TextField
    > > value is only "04/07/2005"?
    > >
    > > Thanks,

    >
    >
    >
    =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=, Jul 4, 2005
    #3
  4. Thanks! This is somewhat of a workaround, but it works nicely!

    "Eliyahu Goldin" wrote:

    > Handle PreRender event. In the event handler loop through the ddl's items
    > and format values programmatically.
    >
    > Eliyahu
    >
    > "charliewest" <> wrote in message
    > news:...
    > > Hello -
    > >
    > > I've binded a dataset to a Drop Down List control on my web form, using

    > C#,
    > > however, the DateTime value is printed in long format. For example:
    > > 04/07/2006 12:00 AM.
    > >
    > > My code is:
    > >
    > > ddlObs.DataSource = ds.Tables["Observations"].DefaultView;
    > > ddlObs.DataTextField = "ObsDate";
    > > ddlObs.DataValueField = "ObsDate";
    > >
    > > How can I use the ddlObs.DataTextFormatString property so that the

    > TextField
    > > value is only "04/07/2005"?
    > >
    > > Thanks,

    >
    >
    >
    =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=, Jul 4, 2005
    #4
  5. Handle PreRender event. In the event handler loop through the ddl's items
    and format values programmatically.

    Eliyahu

    "charliewest" <> wrote in message
    news:...
    > Hello -
    >
    > I've binded a dataset to a Drop Down List control on my web form, using

    C#,
    > however, the DateTime value is printed in long format. For example:
    > 04/07/2006 12:00 AM.
    >
    > My code is:
    >
    > ddlObs.DataSource = ds.Tables["Observations"].DefaultView;
    > ddlObs.DataTextField = "ObsDate";
    > ddlObs.DataValueField = "ObsDate";
    >
    > How can I use the ddlObs.DataTextFormatString property so that the

    TextField
    > value is only "04/07/2005"?
    >
    > Thanks,
    Eliyahu Goldin, Jul 4, 2005
    #5
    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. Wong CS
    Replies:
    0
    Views:
    516
    Wong CS
    Jan 30, 2005
  2. Tony Tone
    Replies:
    0
    Views:
    555
    Tony Tone
    Apr 28, 2006
  3. Tony Tone
    Replies:
    2
    Views:
    7,820
    Marina Levit [MVP]
    Apr 28, 2006
  4. weiwei
    Replies:
    0
    Views:
    1,014
    weiwei
    Jan 5, 2007
  5. Replies:
    5
    Views:
    267
Loading...

Share This Page