c#
  • asp.net
  • 2012-04-24 24 views 0 likes 
    0

    這是我的數據庫值「2012/04/24」我顯示在中繼器的標籤 我必須顯示像這樣的數據庫值12-Apr -2012在中繼器的標籤。 on repeater_ItemDataBound事件我該怎麼做。如何查找中繼器的標籤值(數據庫顏色),並在repeater_ItemDataBound事件中更改文本

    <td class="csstablelisttd"> 
        <asp:Label ID="lblPatientsBirthDate" runat="server" Text='<%#Eval("Patients_Birth_Date")%>'></asp:Label>td> 
        protected void repeaterPatientList_ItemDataBound(object sender, RepeaterItemEventArgs e) 
        { 
    
         Label lblbirthDate = (Label)e.Item.FindControl("lblPatientsBirthDate"); 
    
    
        } 
    

    回答

    0

    試試這個:

    protected void repeaterPatientList_ItemDataBound(object sender, RepeaterItemEventArgs e) 
        { 
    
         Label lblbirthDate = (Label)e.Item.FindControl("lblPatientsBirthDate"); 
         if(lblbirthDate!= null) 
         { 
          DateTime d = DateTime.Parse(lblbirthDate.Text); 
          lblbirthDate.Text = d.ToString("dd-MMM-yyyy"); 
         } 
        } 
    

    如果日期轉換的原因錯誤然後按照DateTime.ParseExact MethodCustom Date and Time Format Strings

    0

    用於格式化日期到一個特定的格式,它可以通過這個來完成:

    <asp:Label ID="lblPatientsBirthDate" runat="server" Text='<%# Eval("Patients_Birth_Date", "{0:dd-MMM-yyyy}")%>' </asp:Label> 
    

    您需要更改repeater_ItemDataBound事件文本。

    希望這會幫助你。

    相關問題