473,474 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Format a date in text of LinkButton

I am trying to get a LinkButton to show a formatted date as part of the text
but it is not working. Below is what I have. MealDate is a valid date, e.g.
11/17/2008. I want it to come out like "Novenber 17". Below is my button
settings.
Thanks.
David

<asp:LinkButton ID="LinkButton1" runat="server"
Text='Sun<br /><%# String.Format(Eval("MealDate","{0:MMMM dd}") %>'
Width="110" CommandArgument='<%# Eval("MealDate", "{0:d}") %>'
CommandName="Insert" OnCommand="LBtnMealEdit_Command">
</asp:LinkButton>
Nov 17 '08 #1
1 5228
I am assuming that your LinkButton is inside of a Template in a Control such
as a Repeater or DataList. When formatting the value of a field when using
the Eval method, you do not need the String.Format. Try the following:

<asp:LinkButton ID="LinkButton1" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,"MealDate","{0: MMMM dd}") %>' Width="110"
CommandArgument='<%# DataBinder.Eval(Container.DataItem,"MealDate", "{0:d}")
%>' CommandName="Insert" OnCommand="LBtnMealEdit_Command"/>

I also noticed that the value for your Text property had a constant and a
databound value. It is usually better to do this using the formatstring
parameter of the DataBinder.Eval method, such as the following:

Text='<%# DataBinder.Eval(Container.DataItem,"MealDate","Sun <br/>{0:MMMM
dd}") %>'

Hopefully this helps.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"David C" <dl*****@lifetimeinc.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>I am trying to get a LinkButton to show a formatted date as part of the
text but it is not working. Below is what I have. MealDate is a valid
date, e.g. 11/17/2008. I want it to come out like "Novenber 17". Below is
my button settings.
Thanks.
David

<asp:LinkButton ID="LinkButton1" runat="server"
Text='Sun<br /><%# String.Format(Eval("MealDate","{0:MMMM dd}") %>'
Width="110" CommandArgument='<%# Eval("MealDate", "{0:d}") %>'
CommandName="Insert" OnCommand="LBtnMealEdit_Command">
</asp:LinkButton>

Nov 18 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Edward Mitchell | last post by:
I have a number of DateTimePicker controls, some set to dates, some set to a format of Time. The controls are all embedded in dialogs. I created the controls by dragging the DateTime picker from...
7
by: M C | last post by:
Hi, This is a problem that has been haunting me for days and I've come to a complete dead-end. I'm using a objectdatasource to select and update a gridview control. Populating with select works...
7
by: Richiep | last post by:
I am trying to get a UK format date of dd/mm/yyyy. Why does the following subroutine not return a valid date in a web form? The date returned is #12:00:00 AM# but the date I entered into the...
0
by: sehguh | last post by:
Hiya Folks, I am Currently using windows xp. Also using Visual Web Developer 2005 and Microsoft Sql server 2005. The main page consists of an aspx page and a master page. The page also...
1
by: sehguh | last post by:
Hello folks I have recently been studying a book called "sams teach yourself asp.net 2.0 in24 hours by scott mitchell. I have reached page 614 but when i tried to run an asp page called...
2
by: thewilldog | last post by:
Hello, I've reviewed the archives here to address the issue, but I'm still running into problems. I've got a table field populated with the record date in text "YYYYMMDD" To convert it into a...
0
by: CDonlan | last post by:
Here is how im exporting //Clear response content and headers response.Clear(); response.ClearContent(); response.ClearHeaders(); //Add header response.AddHeader("content-disposition",...
0
by: Bart | last post by:
Hi, i defined a linkbutton in a gridview. In code-behind, i want to perform the delete query when the user clicks on the linkbutton, but this code gives following error: "Input string was not...
1
by: differentsri | last post by:
THIS IS AN ASP.NET 1.1 APPLICATION IAM TRYING TO UPDATE THE FIELD BUT I AM NOT ABLE TO UPDATE IT? CAN U TELL THE REASON ? IT IS GIVING THE FOLLOWING ERROR BELOW I HAVE ALSO GIVEN THE CODE OF...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.