none
Format TextBox Text RRS feed

  • Question

  • Dear friends,

    Pls help me, i want change the Textbox.Text like 1,234.56

     Dim sqlds As New System.Web.UI.WebControls.SqlDataSource
            sqlds.ConnectionString = ConfigurationManager.ConnectionStrings("cs").ConnectionString
            sqlds.SelectCommand = "SELECT MB002, MB057 FROM INVMB WHERE MB001=@MB001 "
            sqlds.SelectParameters.Clear()
            sqlds.SelectParameters.Add("MB001", ddl.SelectedValue)
            Dim dv As Data.DataView = sqlds.Select(New DataSourceSelectArguments)
            If dv.Count > 0 Then
                lbl.Text = dv.Item(0).Row(0).ToString
                txt.Text = dv.Item(0).Row(1).ToString 
            Else
                lbl.Text = "No Data."
            End If
            dv.Dispose()
            sqlds.Dispose()
    txt.Text = dv.Item(0).Row(1).ToString <== 'Change to format 1,234.56'

    thanks 

    Wednesday, April 18, 2018 5:08 AM

Answers

  • Pls help me, i want change the Textbox.Text like 1,234.56

    The standard numeric formats cover most typical formats:
    https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings

    but you can always use custom numeric formats for special cases:
    https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings

    Wednesday, April 18, 2018 5:14 AM
  • Hi leKHanhVN,

    You can try this:

    TextBox2.Text = "1234.5678"
            TextBox2.Text = Convert.ToDecimal(TextBox2.Text).ToString("N2")

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by LeKhanhVN Friday, April 27, 2018 6:32 AM
    Thursday, April 19, 2018 6:44 AM
    Moderator
  • Hello,

    If using SQL-Server simply perform the formatting in the SELECT statement.

    Here are two choices where (keeping things simple) the WHERE condition doesn't matter what field I filter on, focus on the CONVERT or the CAST methods.

    DECLARE @SomeValue INT = 1;
    
    SELECT  CONVERT(VARCHAR, CAST(MB002 AS MONEY), 1) AS MB002 ,
            MB057
    FROM    INVMB
    WHERE   MB001 = @SomeValue;
    
    SELECT  CAST(FORMAT(MB002, 'N', 'en-US') AS VARCHAR(20)) AS MB002 ,
            MB057
    FROM    INVMB
    WHERE   MB001 = @SomeValue;


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by LeKhanhVN Friday, April 27, 2018 6:32 AM
    Thursday, April 19, 2018 9:41 AM
    Moderator

All replies

  • Pls help me, i want change the Textbox.Text like 1,234.56

    The standard numeric formats cover most typical formats:
    https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings

    but you can always use custom numeric formats for special cases:
    https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings

    Wednesday, April 18, 2018 5:14 AM
  • Hi leKHanhVN,

    You can try this:

    TextBox2.Text = "1234.5678"
            TextBox2.Text = Convert.ToDecimal(TextBox2.Text).ToString("N2")

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by LeKhanhVN Friday, April 27, 2018 6:32 AM
    Thursday, April 19, 2018 6:44 AM
    Moderator
  • Hello,

    If using SQL-Server simply perform the formatting in the SELECT statement.

    Here are two choices where (keeping things simple) the WHERE condition doesn't matter what field I filter on, focus on the CONVERT or the CAST methods.

    DECLARE @SomeValue INT = 1;
    
    SELECT  CONVERT(VARCHAR, CAST(MB002 AS MONEY), 1) AS MB002 ,
            MB057
    FROM    INVMB
    WHERE   MB001 = @SomeValue;
    
    SELECT  CAST(FORMAT(MB002, 'N', 'en-US') AS VARCHAR(20)) AS MB002 ,
            MB057
    FROM    INVMB
    WHERE   MB001 = @SomeValue;


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by LeKhanhVN Friday, April 27, 2018 6:32 AM
    Thursday, April 19, 2018 9:41 AM
    Moderator
  • Thanks 
    Friday, April 27, 2018 6:30 AM
  • Thank a lot

    Need convert Decimal or Integer 

    Friday, April 27, 2018 6:30 AM