Using a DateTime as a DataKeyField

K

Keith Patrick

I have a DataGrid that uses a DateTime coming back from the DB as its
DataKeyField, since that timestamp is the only unique ID I have for the
records I am displaying. The problem is that the DateTime is being stored
down to the second rather than to the millisecond, which ruins the ID. Is
there some way to tell the grid to store that DateTime with millisecond
precision, or at least store the tick count?
 
K

Ken Cox [Microsoft MVP]

Hi Keith,

Are the milliseconds available in the DateTime? If so you might need to
bind to a custom datetime string to get at them.

I'm thinking of something like this:

<columns>
<asp:templatecolumn>
<itemtemplate>
<asp:label id="Label1" runat="server" text='<%#
format(DataBinder.Eval(Container.DataItem, "DateTime"),"yyyyMMdd:HHmmss%ff")
%>'></asp:label>
</itemtemplate>
</asp:templatecolumn>
</columns>

The ff stuff is discussed here:

http://msdn.microsoft.com/library/d...uide/html/cpconcustomnumericformatstrings.asp

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top