Using a DateTime as a DataKeyField

Discussion in 'ASP .Net Datagrid Control' started by Keith Patrick, Jun 6, 2006.

  1. 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?
     
    Keith Patrick, Jun 6, 2006
    #1
    1. Advertisements

  2. 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

    "Keith Patrick" <> wrote in message
    news:...
    >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?
    >
     
    Ken Cox [Microsoft MVP], Jun 7, 2006
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. luna
    Replies:
    1
    Views:
    7,049
  2. Replies:
    0
    Views:
    667
  3. Roman Yakovenko

    datetime 2 win variant datetime

    Roman Yakovenko, Jul 27, 2003, in forum: Python
    Replies:
    0
    Views:
    358
    Roman Yakovenko
    Jul 27, 2003
  4. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    1,031
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  5. mp
    Replies:
    1
    Views:
    667
    John Machin
    Jul 28, 2006
  6. Martin
    Replies:
    0
    Views:
    629
    Martin
    Dec 27, 2008
  7. Replies:
    2
    Views:
    1,052
    M.-A. Lemburg
    Jan 6, 2009
  8. NiklasRTZ

    datetime.datetime. or datetime. ?

    NiklasRTZ, Oct 8, 2009, in forum: Python
    Replies:
    10
    Views:
    746
    niklasr
    Oct 11, 2009
Loading...