如何以特定格式在我的asp.net下拉列表中以特定格式显示日期? [英] How do I display date in a particular format in my asp.net dropdownlist in a particular format?
本文介绍了如何以特定格式在我的asp.net下拉列表中以特定格式显示日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从数据库表中获取数据日期,我将在下拉列表中显示在我的网站中。其中sql server中显示的日期为2015/08/31,目前在我的网站为31/8/2015 12:00:00 AM。
但是我想在2015年8月31日的下拉列表中显示。有人可以教我怎么做吗?感谢您的帮助,提前感谢:)
SQL
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
@DATE date = (CONVERT(varchar,dateadd(d,-(day(getdate())),getdate()),106))
ASPX.CS
ASPX.CS
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;
}
}
}
}
推荐答案
你可以添加
DataTextFormatString = "{0:dd/MM/yyyy}";
或
or
ds.Tables[0].Columns["DATA_DATE"].ToString("dd/MM/yyyy")
select replace((CONVERT( varchar,dateadd(d, - (day(getdate())),getdate()),106)),'',' - ')
select replace((CONVERT(varchar,dateadd(d,-(day(getdate())),getdate()),106)),' ','-')
这篇关于如何以特定格式在我的asp.net下拉列表中以特定格式显示日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文