更改列中的日期格式

时间:2015-03-03 15:03:17

标签: c# asp.net webforms

我的班级目前有一个“交付日期”列,在表格中显示日期格式为2015年2月23日。

我想更改表格中日期的格式,使其看起来像2015年2月23日。有没有办法改变这个?

protected void Page_Load(object sender, EventArgs e)
{
    // Response.Cache.SetCacheability(HttpCacheability.NoCache);
    errormsg.Text = "";
    FutureDeliveryModel theModel = (FutureDeliveryModel)ViewData["FutureDelivery"];
  // litSite.Text = Site.getSite();
    //DataTable StockTable = (DataTable)ViewData["Future"];
    DataTable StockTable =  theModel.GetFuture();
    DataView StockView = StockTable.DefaultView;
    StringBuilder SB = new StringBuilder();
    SB.Append("<table class=\"display\" id=\"dt\" style=\"align: left; width: 99%;\" ");
    SB.Append("rules=\"all\" border=\"1px\" ");
    SB.Append("cellspacing=\"0px\" cellpadding=\"4px\">");

    SB.Append("<thead>");
    SB.Append("<tr></tr>");
    SB.Append("<tr style=\"background-color: Silver; color: #212121; ");
    SB.Append("font-weight: bold\">");
    // Header 
    foreach (DataColumn aColumn in StockTable.Columns)
    {
        SB.Append("<td>");
        SB.Append(aColumn.ColumnName);
        SB.Append("</td>");
    }
    SB.Append("</tr>");
    SB.Append("</thead>");
    SB.Append("<tbody>");
    string Site = " ";
    //detail
    foreach (DataRowView aRowView in StockView)
    {
        int qty = 0;
        int export = 0;
        SB.Append("<tr>");
        foreach (DataColumn aColumn in StockTable.Columns)
        {
            SB.Append("<td style=\"text-align: left\"");
            if (aColumn.ColumnName.ToString().Equals("Site"))
            {
                SB.Append(">");
                Site = aRowView["Site"].ToString();
                SB.Append(Site);
            }
            else
            {

                if (aColumn.ColumnName.ToString().Equals("Quantity")) qty = Convert.ToInt32(aRowView["Quantity"].ToString());
                if (aColumn.ColumnName.ToString().Equals("Export Quantity"))
                {
                    export = Convert.ToInt32(aRowView["Export Quantity"].ToString());
                    if (export != qty && export != 0) SB.Append(" BGCOLOR=\"#00ff00\" ");

                }
                SB.Append(">");
                if (aColumn.ColumnName.ToString().Equals("Export Quantity"))
                {
                    if (export == 0)
                    {
                        SB.Append(" ");
                    }
                    else
                    {
                        SB.Append(aRowView[aColumn.ColumnName].ToString());
                    }
                }
                else
                {
                    if (aColumn.ColumnName.ToString().Equals("Delivery Date"))

                    {
                        SB.Append(aRowView[aColumn.ColumnName].ToString().Substring(0, (aRowView[aColumn.ColumnName].ToString().IndexOf(" "))));
                    //  SB.Append(aRowView[aColumn.ColumnName].ToString().Substring(0, 10));
                    }
                    else
                    {
                        SB.Append(aRowView[aColumn.ColumnName].ToString());
                    }
                }
            }
            SB.Append("</td>");
        }
        SB.Append("</tr>");
    }


    SB.Append("</tbody>");
    SB.Append("</table>");

    litFutureDeliveryDetail.Text = SB.ToString();
    linkBackToMainPage.NavigateUrl = ApplicationUtility.FormatURL("/Stock/Login?action=out");
    linkBack.NavigateUrl = (String)Session["BACKURL"];
    linkUserMaint.NavigateUrl = ApplicationUtility.FormatURL("/Stock/UserMaint");
    screentitle.Text = "Future Deliveries";
    if (theModel.GetErrorMessage().Trim() != "")
    {
        StringBuilder ES = new StringBuilder();
        ES.Append("<table border=1><tr><td  class=\"ErrorText\">");
        ES.Append(theModel.GetErrorMessage().ToString());
        ES.Append("</td></tr></table>");
        errormsg.Text = ES.ToString();
    }
    else
    {
        errormsg.Text = " ";
    }
}

0 个答案:

没有答案