This write up explains how to display only date value in the dropdown for the field containing the date and time value in Asp.net.

We can show only the Date value in two different ways. One is from server-side code and another is from the aspx page.

Server Side

On the server side, we can write the below code to accomplish this.

ddlDate.DataTextField = "Date";
ddlDate.DataValueField = "DateID";
ddlDate.DataTextFormatString = "{0:dd/MM/yyyy}"; //this line formates the field with only date value.
ddlDate.DataSource = Result;
ddlDate.DataBind();

Design Page (Aspx page)

You can use DataTextFormatString on the design page as well. Below is an example code.

<asp:DropDownList ID="ddlDate" runat="server" DataTextFormatString="{0:MM/dd/yyyy}"></asp:DropDownList>

Leave a Reply

Your email address will not be published.