Click here to Skip to main content
15,896,493 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I am getting my data date from my database table which I will display in my website in a dropdown list. which the date displayed in sql server is e.g 2015/08/31 and currently in my website as 31/8/2015 12:00:00AM.

However I would like to display in my drop down list as 31-Aug-2015. Can someone teach me how to do so? Your help is kindly appreciated thanks in advance:)


SQL
SQL
@DATE date = (CONVERT(varchar,dateadd(d,-(day(getdate())),getdate()),106))



ASPX.CS
C#
protected void Page_Load(object sender, EventArgs e)
{
    using (SqlConnection conn = new SqlConnection(dbConn))
    {
        try //Call stored procedure
        {

            SqlCommand cmd = new SqlCommand(spddl, conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            if (!IsPostBack)
            {
                DATE_DOWN_LIST.DataSource = ds.Tables[0];
                DATE_DROP_DOWN_LIST.DataTextField = ds.Tables[0].Columns["DATA_DATE"].ToString();
                DATE_DROP_DOWN_LIST.DataBind();

            }

        }

        catch (Exception i)
        {
            bool exception = true;
            if (exception == true)
            {
                //txtMessage.Text += e.Message;
            }
        }
    }
}
Posted
Comments
F-ES Sitecore 18-Sep-15 8:42am    
You havem't explained the relevance of the sql you have posted such as where it is used, and you haven't shown the mark-up for your gridview so it's hard to give you specific advice. Google "asp.net date format gridview" and you'll find examples of how to use specific formats when binding your fields.

You can add
C#
DataTextFormatString = "{0:dd/MM/yyyy}"; 

or
C#
ds.Tables[0].Columns["DATA_DATE"].ToString("dd/MM/yyyy")
 
Share this answer
 
select replace((CONVERT(varchar,dateadd(d,-(day(getdate())),getdate()),106)),' ','-')
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900