Search code examples
asp.netc#-4.0gridviewitemtemplatedatabound

Trying to bind DateTime.Now in gridview


I am using Visual Web Developer Express 2013 and have created a gridview. When I update other values in the grid, I want txtDate to show the time the values were updated. I set it up as an item template.

<asp:TemplateField HeaderText="txtDate" SortExpression="txtDate">
<itemtemplate><asp:label id="txtDate" runat="server" 
 text="<%# Bind DateTime.Now.ToString()%>"></asp:label>    
</itemtemplate>
</asp:TemplateField>

When I use the above code without Bind - I get the current time displaying. I added Bind so that the current date would insert into the database and I get the following error; Compiler Error Message: CS1026: ) expected

I'm trying to figure out the best way to insert the date when the values are updated. I also tried adding txtDate as a hidden field but that didn't work either.


Solution

  • Uses GetDate() function directly in the insert query, you don't need to show this to the user, because its just for logging purpose as far as I have understood what you want to do.