【发布时间】:2014-06-24 18:18:47
【问题描述】:
我正在从下拉列表中作为完整日期和时间的数据库中检索 DateTime。我需要的只是该下拉列表中该日期时间的月份,以 word 格式显示。
如下:
[System.Web.Services.WebMethod]
public static string OnChainChange(string ChainId)
{
DataTable table = DBHelper.GetMonthList(ChainId.Trim());
string result = string.Empty;
foreach (DataRow dr in table.Rows)
{
DateTime thisDate = Convert.ToDateTime(dr["FromDate"].ToString());
result += new ListItem(thisDate.ToString("MMMM"), thisDate.Month.ToString("MMMM"));
//result += dr["FromDate"].ToString() + ";";
}
return result;
}
LB - 这个问题是不同的。我正在尝试将其作为新的 listItem 来执行。我了解如何转换 DateTime int。我希望你能找到一个重复的答案! :)
【问题讨论】:
-
问题出在哪里?
-
@L.B,问题不是获取月份名称,而是
thisDate.Month.ToString("MMMM"),尝试使用DateTime格式转换int值
标签: c# asp.net web-services datetime drop-down-menu