Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the date format of a DataBinder.Eval in asp.net?

I'm trying to figure out how to change the datetime format so just the date will show up.

            <asp:Repeater ID="RepeaterActions" runat="server">             <ItemTemplate>                 <li>                     <span class="historyDate"><%#DataBinder.Eval(Container.DataItem, "ActionListDate")%></span>                     <span class="historyName"><%#DataBinder.Eval(Container.DataItem, "LeadActionName")%></span><br />                     <span class="historyNotes"><%#DataBinder.Eval(Container.DataItem, "ActionListNote")%></span>                 </li>             </ItemTemplate>         </asp:Repeater> 

I'm guessing it's something in between the <% %>, but I'm not sure.

My code behind is:

<pre>         protected void RepeaterActionsFill()     {          string sql = @"  select a.ActionListDate, a.LeadListID,  a.ActionListNote,  l.LeadActionName from ActionLists as a INNER JOIN LeadActions as l ON a.LeadActionID = l.LeadActionID where a.LeadListID = " + Convert.ToInt32(Request["id"].ToString());          RepeaterActions.DataSource = DBUtil.FillDataReader(sql);         RepeaterActions.DataBind();     } </pre> 

Currently, it comes accross looking like this:

HTML View

And what I'm looking for is for the time stamp to be gone there.

Any help is appreciated.

EDIT:

Here is what I was looking for:

            <asp:Repeater ID="RepeaterActions" runat="server">             <ItemTemplate>                 <li>                     <span class="historyDate"><%#DataBinder.Eval(Container.DataItem, "ActionListDate", "{0:M/d/yy}")%></span>                     <span class="historyName"><%#DataBinder.Eval(Container.DataItem, "LeadActionName")%></span><br />                     <span class="historyNotes"><%#DataBinder.Eval(Container.DataItem, "ActionListNote")%></span>                 </li>             </ItemTemplate>         </asp:Repeater> 
like image 227
Barrett Kuethen Avatar asked Oct 01 '11 16:10

Barrett Kuethen


People also ask

How can get date in dd mm yyyy format in asp net?

Solution 1Text=System. DateTime. Now. ToString("dd/MM/yyyy");

What is use of Databinder eval in asp net?

Eval) function is used to bind data in controls inside GridView, DataList, Repeater, DetailsView, etc. and using string. Format multiple values can be set to a single control.


2 Answers

give the format e.g:

<%# DataBinder.Eval(Container.DataItem, "ActionListDate", "{0:d/M/yyyy hh:mm:ss tt}") %> 
like image 197
Damith Avatar answered Sep 19 '22 17:09

Damith


<%# string.Format("{0:ddd MMM yyyy}", Eval("ActionListDate"))%>

like image 38
Christian Avatar answered Sep 20 '22 17:09

Christian