DateTimeFormat

G

gh

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:
 
G

Guest

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:

C#?

Try string.Format
 
G

George Ter-Saakov

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
 
G

gh

George said:
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
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
 
G

George Ter-Saakov

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

gh

George said:
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.
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
 
G

Guest

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:HyperLin­k>

TIA- Hide quoted text -

- 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/quicks...ctrlref/webctrl/imagebutton/doc_imagebut.aspx

..NET server control cannot work without runat=server.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top