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