Passing DateTime Values Through GridView HyperLinkField
This question was asked in the www.asp.net forums. The scenario is that you want to pass the DateTime value to another page using the GridView HyperLinkField column. If your DateTime is coming from the database in the form of 2006-11-22 13:10:42.840 which shows the date and the time component then you won't be able to display it as a link using the HyperLinkField. The reason is that it contains colons (:) and colons are not allows to be the part of the link. If you remove the colons it will work as expected. A better solution is to pass only the date component. I am pretty sure that 95% of the users will only require the date component if so you can extract it using the T-SQL query.
SELECT UserID, FirstName, CONVERT(varchar(10), DateCreated,110) AS DateCreated FROM Users
The GridView code looks something like this:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:HyperLinkField DataTextField="FullName" DataNavigateUrlFields="UserID,DateCreated" DataNavigateUrlFormatString="~/Demo.aspx?userID={0}&dateCreated={1}" />
</Columns>
</asp:GridView>
Comment Notification
If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using