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

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

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. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    734
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    556
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    403
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    350
    Martin
    Dec 27, 2008
  5. Replies:
    2
    Views:
    775
    M.-A. Lemburg
    Jan 6, 2009
Loading...

Share This Page