how to format datetime in dropdownlist control

G

Guest

Hi expart,
I have facing the problem of formatting the datetime in Dropdownlist.
I am using Data Reader to retrive the date data from Sql2000 server
and bind to DropDownList Control.
The default format showing in the DropDownList is "MM/dd/yyyy".
I want to change the format to "dd/MM/yyyy".
The code sample as below.

sqlconn.open()
dim sqlcomm as sqlclient.sqlcommand
sqlcomm.commandtext = "select testdate from testtable"
sqlcomm.commandtype= commandtype.text
sqlcomm.connection= sqlconn
dim sqldareader as sqlclient.sqldatareader
sqldareader = sqlcomm.executereader

testdropdownlist.datasource=sqldareader
testdropdownlist.databind

anyone can help me how to program to change testdropdownlist datetime format.
 
P

Peter Huang [MSFT]

Hi

It seems that you are using the DropDownList on WebForm.
We can use the DataTextFormatString property to do the formatting.
e.g.
dropdownlist1.DataTextFormatString ="{0:dd/MM/yyyy}"

ListControl.DataTextFormatString Property
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwebuiwebcontrolslistcontrolclassdatatextformatstringtopic.asp

DateTimeFormatInfo Class
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemglobalizationdatetimeformatinfoclasstopic.asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Top