Format a date in text of LinkButton

Discussion in 'ASP .Net' started by David C, Nov 17, 2008.

  1. David C

    David C Guest

    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>
    David C, Nov 17, 2008
    #1
    1. Advertising

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

    http://www.nathansokalski.com/

    "David C" <> wrote in message
    news:%...
    >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>
    >
    Nathan Sokalski, Nov 18, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Candy
    Replies:
    2
    Views:
    1,159
    Janaka
    Feb 18, 2004
  2. Sathyaish
    Replies:
    3
    Views:
    3,102
    Sathyaish
    Sep 8, 2005
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,251
    Michael Borgwardt
    May 30, 2004
  4. Chu
    Replies:
    3
    Views:
    4,186
    Shawn
    Aug 15, 2006
  5. Sathyaish

    Linkbutton does not look like a linkbutton

    Sathyaish, Sep 8, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    184
    Sathyaish
    Sep 8, 2005
Loading...

Share This Page