この質問は以前に尋ねられています。しかし、.NET 4.0 Webフォームアプリケーションでは、私は同じデータグリッドを持ち、同じコードが、純4.5.1 Webフォームアプリケーションを使用すると、フォーマットが異なっているASP.Net Datagrid DataFormat文字列に日付の書式が正しく設定されていません
.NET 4.0
<asp:BoundColumn DataField="Investment Date" DataFormatString="{0:d}" HeaderText="Investment Date" HeaderStyle-CssClass="centre" ItemStyle-CssClass="centre"></asp:BoundColumn>
は日付を生成しますDD/MM/YYYYの形式 - 私はその結果である
の.Net 4.5.1
<asp:BoundColumn DataField="Investment Date" DataFormatString="{0:dd-MM-yyyy}" HeaderText="Investment Date" HeaderStyle-CssClass="centre" ItemStyle-CssClass="centre"></asp:BoundColumn>
と
012の後私はここで他のスタック質問で- cant format datetime using dataformatstring
- How to fix date format in ASP .NET BoundField (DataFormatString)?
- Date format without time in ASP.NET Gridview
:MM:
<asp:BoundColumn DataField="Investment Date" DataFormatString="{0:d}" HeaderText="Investment Date" HeaderStyle-CssClass="centre" ItemStyle-CssClass="centre"></asp:BoundColumn>
はDD/MM/YYYYのHHの結果を生成します
私はすでに試したことがあります。私はクレイジーつもりではなかったことを確認した可能性がちょうどそのよう
は、私は、あまりにもここ
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspxを書式設定をチェックして、これは私があまりにも正しいだということを私に伝えます。
これは、データがデータテーブル
protected void bttnAddExisting_Click(object sender, EventArgs e)
{
var ei = new ExistingInvestments();
dgExistingInvestments.DataSource = ei.dtExistingInvestments(Session, ddlExistingFundName, ddlExistingFundRiskProfile, ddlExistingFundCustomerName, txtExistingFundInvestmentDate);
dgExistingInvestments.DataBind();
}
に追加する方法であり、これはクラスExistingInvestments
public class ExistingInvestments
{
public string FundName { get; set; }
public string FundRiskProfile { get; set; }
public string CustomerName { get; set; }
public DateTime InvestmentDate { get; set; }
public DataTable dtExistingInvestments(HttpSessionState Session, DropDownList ddlExistingFundName, DropDownList ddlExistingFundRiskProfile,
DropDownList ddlExistingFundCustomerName, TextBox txtExistingFundInvestmentDate)
{
if (Session["ExistingInvestmentsTable"] == null)
{
var dtExistingFund = new DataTable();
dtExistingFund.Columns.Add("Fund Name");
dtExistingFund.Columns.Add("Fund Risk Profile");
dtExistingFund.Columns.Add("Customer Name");
dtExistingFund.Columns.Add("Investment Date");
if (string.IsNullOrEmpty(txtExistingFundInvestmentDate.Text))
{
dtExistingFund.Rows.Add(ddlExistingFundName.SelectedValue, ddlExistingFundRiskProfile.SelectedValue,
ddlExistingFundCustomerName.SelectedValue, string.Empty);
}
else
{
dtExistingFund.Rows.Add(ddlExistingFundName.SelectedValue, ddlExistingFundRiskProfile.SelectedValue,
ddlExistingFundCustomerName.SelectedValue, Convert.ToDateTime(txtExistingFundInvestmentDate.Text));
}
Session["ExistingInvestmentsTable"] = dtExistingFund;
return dtExistingFund;
}
else
{
var dt = (DataTable)Session["ExistingInvestmentsTable"];
if (string.IsNullOrEmpty(txtExistingFundInvestmentDate.Text))
{
dt.Rows.Add(ddlExistingFundName.SelectedValue, ddlExistingFundRiskProfile.SelectedValue,
ddlExistingFundCustomerName.SelectedValue, string.Empty);
}
else
{
dt.Rows.Add(ddlExistingFundName.SelectedValue, ddlExistingFundRiskProfile.SelectedValue,
ddlExistingFundCustomerName.SelectedValue, Convert.ToDateTime(txtExistingFundInvestmentDate.Text.Trim()));
}
Session["ExistingInvestmentsTable"] = dt;
return dt;
}
}
}
どれ
、すべてが大幅に役立つ誰もがそれは素晴らしいだろう手助けができれば を高く評価しています。
あなたは質問にあなたがしたい、実際の結果を書くのを忘れて、または多分私は少し器用だし、それが –
良い点:)を逃しました! dd/MM/yyyyの後にimを編集して、今質問を編集してください –