I am trying to format label text

I want mine to Labeluse the format {0:c2}; however, it does not work when I do it as follows:

Client Code:

<asp:Label ID="Label4" runat="server" Text="Label" StringFormat="{}{0:c2}"></asp:Label>

Server code (when loading the page):

Dim dvSql7 As DataView = DirectCast(SqlDataSource7.Select(DataSourceSelectArguments.Empty), DataView)
    For Each drvSql7 As DataRowView In dvSql7
        Label4.Text = drvSql7("goal").ToString()

    Next

What could be the problem? Thanks in advance for any help.

+3
source share
1 answer

There is no StringFormatLabel control property . What you need to do is format the string before it is assigned to the property Label.Text:

Label4.Text = Convert.ToDecimal(drvSql7("goal")).ToString("c")

+6
source

All Articles