【发布时间】:2016-07-21 00:39:00
【问题描述】:
我试图通过在 DataBound 事件中放置代码来格式化 GridView 控件中的列。它不起作用,因为由于某种原因,未填充列集合。控件已绑定,它可以工作,但列集合显示计数为零,因此代码不起作用。
想法?
protected void gvReport_DataBound(object sender, EventArgs e)
{
for (int columnIndex = 0; columnIndex <= gvReport.Columns.Count - 1; columnIndex += 1)
{
var col = ((BoundField)gvReport.Columns[columnIndex]);
if (object.ReferenceEquals(col.DataField.GetType(), typeof(System.DateTime)))
col.DataFormatString = "MM/dd/yyyy";
}
}
【问题讨论】: