Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    [2.0-VB] Formattazione data all'interno di un datalist

    All'interno di un controllo datalist, visualizzo il risultato di una query e, tra i vari campi, ce n'è uno che contiene una data: come posso fare per formattarla, visto che mi occorre visualizzarla solo parzialmente? Grazie...
    ...I took a heavenly ride through our silence I knew the moment had arrived
    For killing the past and coming back to life...

    ThePinkBox

  2. #2
    Non ho mai usato il datalist ma con la GridView in genere mi comporto in questo modo :

    codice:
    <ItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%# FormattaData(DataBinder.Eval(Container.DataItem,"DataCreazione")) %>'></asp:Label>
    </ItemTemplate>
    e poi nel code behind implemento la funzione FormattaData()

    codice:
        /// <summary>
        /// FormattaData
        /// </summary>
        /// <param name="ValoreData"></param>
        /// <returns></returns>
        public string FormattaData(object ValoreData) 
        {
            DateTime DateRet;
            if (DateTime.TryParse(ValoreData.ToString(), out DateRet))
            {
                return DateRet.ToString("dd-MM-yyyy");
            }
            else
            {
                return "";
            }
            
        }
    ...NO ONE IS INNOCENT ANYMORE...

  3. #3
    Ok, appena rientro stasera provo e ti faccio sapere...
    ...I took a heavenly ride through our silence I knew the moment had arrived
    For killing the past and coming back to life...

    ThePinkBox

  4. #4
    Funziona... Ecco le mie modifiche...

    codice:
    <asp:Label ID="provaLabel" runat="server" Text='<%# FormattaData(Eval("campodata")) %>' />
    ...questo nel DataList, mentre la funzione è questa...

    codice:
    Function FormattaData(ByVal DD) As String
            Dim Data As String
            Data = Day(CDate(DD)) & " "
            Select Case Month(CDate(DD))
                Case 1
                    Data = Data & "Gen."
                Case 2
                    Data = Data & "Feb."
                Case 3
                    Data = Data & "Mar."
                Case 4
                    Data = Data & "Apr."
                Case 5
                    Data = Data & "Mag."
                Case 6
                    Data = Data & "Giu."
                Case 7
                    Data = Data & "Lug."
                Case 8
                    Data = Data & "Ago."
                Case 9
                    Data = Data & "Set."
                Case 10
                    Data = Data & "Ott."
                Case 11
                    Data = Data & "Nov."
                Case 12
                    Data = Data & "Dic."
            End Select
            Data = Data & " " & Year(CDate(DD))
            Return Data
        End Function
    Grazie mille.....
    ...I took a heavenly ride through our silence I knew the moment had arrived
    For killing the past and coming back to life...

    ThePinkBox

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.