Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

DateTimeFormat

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gh - 01 Oct 2007 17:57 GMT
I am trying to format a datetime in a datalist label.  Below is the aspx
code I have, but I get an error: The name 'Format' does not exist in the
current context.

How do I format the datetime to display the date portion only in the label.

TIA

  <asp:Label id="ProjectDateLabel" runat="server"
text='<%#Format(Eval("ProjectDate"),"d/M/yyyy")%>'></asp:Label>Address:
Alexey Smirnov - 01 Oct 2007 19:17 GMT
> I am trying to format a datetime in a datalist label.  Below is the aspx
> code I have, but I get an error: The name 'Format' does not exist in the
[quoted text clipped - 6 lines]
>    <asp:Label id="ProjectDateLabel" runat="server"
> text='<%#Format(Eval("ProjectDate"),"d/M/yyyy")%>'></asp:Label>Address:

C#?

Try string.Format
George Ter-Saakov - 01 Oct 2007 19:48 GMT
Try this
<%# DataBinder.Eval(Container.DataItem, "ProjectDate", "{0:dd/MM/yyyy}") %>

Or my guess <%# Eval("ProjectDate", "{0:dd/MM/yyyy}") %>  (never worked with
that, awlays used DataBinder object)

George

>I am trying to format a datetime in a datalist label.  Below is the aspx
>code I have, but I get an error: The name 'Format' does not exist in the
[quoted text clipped - 7 lines]
>   <asp:Label id="ProjectDateLabel" runat="server"
> text='<%#Format(Eval("ProjectDate"),"d/M/yyyy")%>'></asp:Label>Address:
gh - 01 Oct 2007 20:36 GMT
> Try this
> <%# DataBinder.Eval(Container.DataItem, "ProjectDate", "{0:dd/MM/yyyy}") %>
[quoted text clipped - 15 lines]
>>  <asp:Label id="ProjectDateLabel" runat="server"
>>text='<%#Format(Eval("ProjectDate"),"d/M/yyyy")%>'></asp:Label>Address:

George:

That did it.  Do you by chance know how to make an image a hyper link?
Below is the code I have.

  <asp:Image id="Image1" runat="server" height="125px" width="125px"
imagealign="Left" imageurl='<%# "images/" +
DataBinder.Eval(Container.DataItem, "PHOTOID")%>'></asp:image>&nbsp;PhotoID:

TIA
George Ter-Saakov - 01 Oct 2007 20:57 GMT
Do not try to make everything as a Server control. Usually image should not
be a server control.

Do something like this
<a href="images/<%# DataBinder.Eval(Container.DataItem, "PHOTOID")%>" >
<img src="images/<%# DataBinder.Eval(Container.DataItem, "PHOTOID")%>"
height="125px" width="125px" >
</a>

PS: Nothing prevents you from making it as a server control and use
<asp:Image> <asp:Link>. You will just consume more resources if you are not
using them as a server controls.

George.

> Do you by chance know how to make an image a hyper link? Below is the code
> I have.
[quoted text clipped - 5 lines]
>
> TIA
gh - 02 Oct 2007 01:24 GMT
> Do not try to make everything as a Server control. Usually image should not
> be a server control.
[quoted text clipped - 20 lines]
>>
>>TIA

George:

When the image is clicked I have a value of anther field I need to pass
in the url.  I use the code below in a link to do this and it works
great.  Can this be done without using runat server?  Anyway the

<asp:HyperLink runat="server" navigateurl='<%#"selphotos.aspx?id="+
DataBinder.Eval(Container.DataItem, "ExternalId").ToString()%>'
id="Hyperlink1"><%#DataBinder.Eval(Container.DataItem,
"PrjID")%></asp:HyperLink>

What I was trying was to use the code below with the image, but it
doesn' t act as a link, when clicked.

<asp:HyperLink><asp:Image id="Image1" runat="server" height="125px"
width="125px"
imagealign="Left" runat="server" navigateurl='<%#"selphotos.aspx?id="+
DataBinder.Eval(Container.DataItem, "ExternalId").ToString()%>'
id="Hyperlink1"><%# "images/" +
DataBinder.Eval(Container.DataItem,"PHOTOID")%>'></asp:image></asp:HyperLink>

TIA
Alexey Smirnov - 02 Oct 2007 07:56 GMT
> > Do not try to make everything as a Server control. Usually image should not
> > be a server control.
[quoted text clipped - 45 lines]
>
> - Show quoted text -

An image with a hyper link on html page can be created using a mix of
<a> and <img> tags. In ASP.NET, the <img> tag is rendered through the
Image control and <a> through the HyperLink. Note, neither <img> nor
Image control has a destination link property (navigateurl in your
case).

There is another control, named ImageButton, take a look, maybe this
helps
http://samples.gotdotnet.com/quickstart/aspplus/samples/webforms/ctrlref/webctrl
/imagebutton/doc_imagebut.aspx


.NET server control cannot work without runat=server.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.