2011-10-01 8 views
31

मैं डेटाटाइम प्रारूप को बदलने का तरीका जानने का प्रयास कर रहा हूं, इसलिए बस तारीख दिखाई देगी।मैं asp.net में DataBinder.Eval का दिनांक प्रारूप कैसे बदलूं?

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

मैं इसे अनुमान लगा रहा हूँ <%%> के बीच में कुछ है, लेकिन मैं यकीन नहीं है।

मेरे कोड के पीछे है:

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

वर्तमान में, यह इस तरह लग रही करवाते हैं आता है:

HTML View

और क्या मैं के लिए देख रहा हूँ के लिए समय स्टाम्प वहां गए किया जा रहा है ।

किसी भी मदद की सराहना की जाती है।

संपादित करें:

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

उत्तर

44

प्रारूप जैसे देना कोड पीछे:

public string makeShortDate(object oDate) 
{ 
    if (oDate is DBNull) { 
     return ""; 
    } else { 
     DateTime dDate = Convert.ToDateTime(oDate); 
     string sDate = dDate.ToShortDateString(); 
     return sDate; 
    }   
} 

और XHTML में इस का उपयोग करें: पाठ = '<% # makeShortDate (DataBinder.Eval (Container.DataItem, "MyDate"))%>' आप किसी भी प्रकार के लिए इस संशोधित कर सकते हैं।

-3

अभी इस कोड का परीक्षण नहीं किया जा सकता लेकिन की तर्ज पर कुछ:

यहाँ है कि मैं क्या तलाश कर रहा था?

<%# DataBinder.Eval(Container.DataItem, "ActionListDate", "{0:d/M/yyyy hh:mm:ss tt}") %> 
+0

यह तब से काम नहीं करता है। ToString() कोई पैरामीटर नहीं ले सकता .. – banging

0

भी आपका अनुसरण करने के लिए अपने TSQL बदल सकते हैं या सिर्फ Convert.ToInt32()

string sql = string.Format(@"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 = {0};", Request["id"]); 
+0

आपको किसी भी एसक्यूएल इंजेक्शन के लिए अनुरोध ["आईडी"] भी जांचना चाहिए ... – Christian

1

मैं में रखते निकालें:

<%#DataBinder.Eval(Container.DataItem, "ActionListDate").ToString("dd/MM/yyyy") %> 
संबंधित मुद्दे