I am retrieving date values from dataset(_dsst) and populating them in dropdown list(drpStartYear).
Since I am storing date as datetime datatype, I am
Below code worked for me, I was using DataValueField, which didnot allow me to use DataTextFormatString, So When I changed it to DataTextField, I got intended results :)
drpStartYear.DataSource = _dstt.Tables["tbSettings"].DefaultView;
drpStartYear.DataTextField = "StartDate";
drpStartYear.DataTextFormatString = "{0:d}";
drpStartYear.DataBind();
You have to set DataTextField as well -
drpStartYear.DataValueField = "StartDate";
drpStartYear.DataTextField = "StartDate";
drpStartYear.DataTextFormatString = "{0:dd-MM-yyyy}";
drpStartYear.DataBind();
Did you try:
drpStartYear.DataTextFormatString = "0:dd/MM/yyyy HH:mm:ss";
drpStartYear.DataTextFormatString = "{0:dd-MM-yyyy}";
drpStartYear.DataTextField = "StartDate";
or you can set this in your mark-up as follows:
<asp:DropDownList
id="drpStartYear"
runat="server"
DataTextField = "StartDate"
DataTextFormatString="{0:dd-MM-yyyy}"/>
drpStartYear.DataTextFormatString = "{0:dd-MM-yyyy}";
EDIT: Add this:
drpStartYear.DataTextField = "StartDate";