You must Sign In to post a response.
  • Category: ASP.NET

    How to use delimiter in textbox in asp.net

    in a textbox in run time if i put 1000 means if i enter 1000 i need to show like this 1,000 in the textbox in runtime
  • #767357
    Hi,

    OnKeyPress event of textbox you can wrote below lines of code


    Protected void txt1_KeyPress(object sender, KeyPressEventArgs e)
    {
    e.Handled =!char.IsDigit(e.KeyChar) && e.KeyChar !=(char)8;
    txt1.Text=string.Format("{0:n0}", Double.Parse(txt1.Text));
    }


    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #767377
    Hi
    try this code



    <asp:TextBox
    ID="budgetText"
    runat="server"
    Text='<%# string.Format(CultureInfo.InvariantCulture, "{0:#,0.00}", Bind("Budget")) %>'



    refer his url

    "forums.asp.net/t/1616010.aspx?Implementation+of+thousand+separator+for+a+Textbox"

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #767378
    when you assign a value to textbox you can use 'string.Format' method, it just Converts the value of objects to strings based on the formats specified and inserts them into another string

    textBox1.Text = string.Format("{0:#,##0.00}", double.Parse(textBox1.Text));

    above code will works as expected just you need to make sure that input text should be only Integer or Double value
    or simply you can use globalization as Indian, see below snippet

    textBox1.Text = string.Format(System.Globalization.CultureInfo.GetCultureInfo("id-ID"), "{0:#,##0.00}", double.Parse(textBox1.Text));

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


  • Sign In to post your comments