大概有下面几种方法吧: 1、可以指定 BoundColumn 的 DataFormatString,例如: DataFormatString="{0:MM/dd/yyyy}" 其他格式可以参考 String.Format(Formatting Overview/Formatting Types)。 2、设定 TemplateColumn,这样就可以用其他控件来显示/修改数据; 3、在 DataGrid_ItemDataBound 来修改显示格式: Dim drv As DataRowView Dim lit As ListItemTypelit = e.Item.ItemType' Make sure we're not in header or footer If lit = ListItemType.Item _ OrElse lit = ListItemType.AlternatingItem _ OrElse lit = ListItemType.SelectedItem _ Then ' Get the DataRowView associated with current item drv = CType(e.Item.DataItem, DataRowView) ' Formatting cells text... e.Item.Cells(0).Text = PublicUtil.FormatSS(drv("integer_filed")) e.Item.Cells(2).Text = CType(drv("date_field"), Date).ToString("MM/yyy") Dim txt As TextBox ' Also can find a control in template column and ... txt = e.Item.FindControl("TextBox1") txt.Text = "Any format you want" End If
1、可以指定 BoundColumn 的 DataFormatString,例如:
DataFormatString="{0:MM/dd/yyyy}"
其他格式可以参考 String.Format(Formatting Overview/Formatting Types)。
2、设定 TemplateColumn,这样就可以用其他控件来显示/修改数据;
3、在 DataGrid_ItemDataBound 来修改显示格式:
Dim drv As DataRowView
Dim lit As ListItemTypelit = e.Item.ItemType' Make sure we're not in header or footer
If lit = ListItemType.Item _
OrElse lit = ListItemType.AlternatingItem _
OrElse lit = ListItemType.SelectedItem _
Then
' Get the DataRowView associated with current item
drv = CType(e.Item.DataItem, DataRowView) ' Formatting cells text...
e.Item.Cells(0).Text = PublicUtil.FormatSS(drv("integer_filed"))
e.Item.Cells(2).Text = CType(drv("date_field"), Date).ToString("MM/yyy") Dim txt As TextBox ' Also can find a control in template column and ...
txt = e.Item.FindControl("TextBox1")
txt.Text = "Any format you want"
End If