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

G

Guest

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,
 
G

Guest

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 said:
Check the:
DataTextFormatString() Property on DropDownLists

/Lars

charliewest said:
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,
 
G

Guest

Thanks! This is somewhat of a workaround, but it works nicely!

Eliyahu Goldin said:
Handle PreRender event. In the event handler loop through the ddl's items
and format values programmatically.

Eliyahu

charliewest said:
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,
 
E

Eliyahu Goldin

Handle PreRender event. In the event handler loop through the ddl's items
and format values programmatically.

Eliyahu
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top