Welcome to AspAdvice Sign in | Join | Help

AzamSharp

Some day I will know everything I hope that day never comes

Syndication

Tags

Navigation

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>

Sponsor

Published Wednesday, November 22, 2006 11:12 PM by azamsharp

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 RSS

Comments

# Web Links 11.26.2006 &laquo; Rhonda Tipton&#8217;s WebLog @ Sunday, November 26, 2006 7:04 PM

PingBack from http://rtipton.wordpress.com/2006/11/26/web-links-11262006/

Web Links 11.26.2006 « Rhonda Tipton’s WebLog

# re: Passing DateTime Values Through GridView HyperLinkField @ Saturday, July 07, 2007 4:02 AM

How do i receive them at the other end. suppose i want to display information related to teh selected value on the 2nd page what shouldi do ? please reply..

Meta_dude

Leave a Comment

(required) 
required 
(required) 
Enter the code you see below