RE: DataGrid with date column that is sometimes blank
From: Steven Cheng[MSFT] (v-schang_at_online.microsoft.com)
Date: 01/20/05
- Next message: PrasantH: "Removing Link from Button column"
- Previous message: Vsiah: "Sort a Datagrid with DataRelation"
- In reply to: Stephen Walch: "DataGrid with date column that is sometimes blank"
- Next in thread: Elton Wang: "DataGrid with date column that is sometimes blank"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 20 Jan 2005 05:42:30 GMT
Hi Steve,
Thanks for your posting. As for the displaying DateTime value in DataGRid
column according to its Ticks value question you mentioned, I think we
should use a Template Columns instead of the simple BoundColumn. Are you
currently using BoundColunn to display data? The BoundColumn only simpley
display the certain field retrieved from the datasource via field name and
we can do some additional simple formatting. If you have some more complex
code logical to display the data value, I think it's quite easy to use the
Template Column in which we can use databind statement to embeded our
custom defined helper functions. For exmple:
the following datagrid use a Template Column to display a dateTime field
and use a helper function in the codebehind page class to format the output
according to the dateTime value's Ticks:
<asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<%# GetFormattedTime((DateTime)DataBinder.Eval(Container.DataItem,
"date")) %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
protected string GetFormattedTime(DateTime date)
{
if(date.Ticks == 0)
{
return "Empty Time";
}
return date.ToShortTimeString();
}
And here is a certain tech article introduce the Templates in asp.net :
#Understanding Templates in ASP.NET
http://msdn.microsoft.com/msdnmag/issues/02/01/cutting/default.aspx
Hope also helps. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
- Next message: PrasantH: "Removing Link from Button column"
- Previous message: Vsiah: "Sort a Datagrid with DataRelation"
- In reply to: Stephen Walch: "DataGrid with date column that is sometimes blank"
- Next in thread: Elton Wang: "DataGrid with date column that is sometimes blank"
- Messages sorted by: [ date ] [ thread ]