Format a date in text of LinkButton

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David C

    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:LinkButt on ID="LinkButton1 " runat="server"
    Text='Sun<br /><%# String.Format(E val("MealDate", "{0:MMMM dd}") %>'
    Width="110" CommandArgument ='<%# Eval("MealDate" , "{0:d}") %>'
    CommandName="In sert" OnCommand="LBtn MealEdit_Comman d">
    </asp:LinkButton>


  • Nathan Sokalski

    #2
    Re: Format a date in text of LinkButton

    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:LinkButt on ID="LinkButton1 " runat="server" Text='<%#
    DataBinder.Eval (Container.Data Item,"MealDate" ,"{0:MMMM dd}") %>' Width="110"
    CommandArgument ='<%# DataBinder.Eval (Container.Data Item,"MealDate" , "{0:d}")
    %>' CommandName="In sert" OnCommand="LBtn MealEdit_Comman d"/>

    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.Data Item,"MealDate" ,"Sun<br/>{0:MMMM
    dd}") %>'

    Hopefully this helps.
    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


    "David C" <dlchase@lifeti meinc.comwrote in message
    news:%23LjFkMPS JHA.4084@TK2MSF TNGP04.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:LinkButt on ID="LinkButton1 " runat="server"
    Text='Sun<br /><%# String.Format(E val("MealDate", "{0:MMMM dd}") %>'
    Width="110" CommandArgument ='<%# Eval("MealDate" , "{0:d}") %>'
    CommandName="In sert" OnCommand="LBtn MealEdit_Comman d">
    </asp:LinkButton>
    >

    Comment

    Working...