CodeBehind中的DataFormatString

时间:2017-06-09 19:06:30

标签: c# asp.net gridview

我想修改Gridview中显示日期的方式, 我试过这个:

private void Temp_RowDataBound(object sender, GridViewRowEventArgs e)     
{
        if(e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[6].Attributes.Add("DataFormatString", "{0:d}");
        }
}

由于gridvirws在runnig中生成,我不能像通常那样做:

<asp:BoundField DataFormatString="{0:d}" DataField="Date" HeaderText="Date" ReadOnly="True" SortExpression="Date" />

所以我可以这样做吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

如果您不知道您的网页会有多少网格,那么使用Repeater可能是个好主意。如果您这样做,您将能够像您所说的那样使用DataFormatString的{​​{1}}属性。