如何创建数字文本框 [英] How to create numeric textbox

查看:82
本文介绍了如何创建数字文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建数字文本框,该文本框仅检索数字类型值,并且仅接受数字值.例如,我们在asp.net中创建文本框,我们使用TextBox1.Text检索值,同时获得数值,我们应该给
Convert.ToDouble(TextBox1.Text).因此,如何在不提供Convert.Todouble()函数的情况下获取数字值,例如TextBox1.NText就是在提供数字值.如何创建它.请任何人帮助我.

感谢u

I want to create numeric textbox, which is retrieve numeric type value only and accepts only numeric values. For example we create textbox in asp.net we retrieve the values use TextBox1.Text, at the same time we get the numeric values, We should give
Convert.ToDouble(TextBox1.Text). So How to get the numeric value without giving Convert.Todouble() function, like TextBox1.NText which is giving numeric value. How to create it. Please anybody help me.

Thanking u

推荐答案

您可以创建一个自定义控件,该控件可以从文本框派生,也可以封装文本框并包含进行转换的AsDouble属性.不过,它是一把大锤,可以裂开很小的螺母.
或者,您可以使用Google:数字文本框asp.net [
You could create a custom control which either derives from a textbox, or encapsulates a textbox and contains an AsDouble property which does the conversion. It''s a sledgehammer to crack a teeny tiny nut though.
Alternatively, you could use Google: Numeric textbox asp.net[^] - there are quite a few out there which also restrict the input to numeric values.


创建数字文本框
方法1:屏蔽文本框以仅接受数字.通过UI不会输入任何字母或特殊字符.您可以使用正则表达式& Javascript
方法2:创建一个自定义控件,该控件看起来像文本框,但只包含数字.向其公开一个NText属性,该属性将为您提供与输入的文本等效的数字.
方法3:更改现有普通文本框的行为.覆盖.Text方法或方法,并将仅从输入内容中提取数字的逻辑放回去,并返回该结果.

根据您的方便程度和要求尝试任何操作.
create numeric textbox
Method 1: Mask your textbox to only accept numbers. It will not take any alphabet or special characters as input through UI. You can do this using Regular expression & Javascript
Method 2: Create a custom control that looks like a textbox but only takes numbers. Expose a NText property to it that will give you the number equivalent of the text entered.
Method 3: Change the behaviour of your existing normal textbox. Override the .Text method or method and put your logic of only extracting numbers from whatever was entered and return back that result.

Try anything based on your ease and requirement.


请仔细阅读

创建数字TextBox控件 [
Go through this

Creating a Numeric TextBox Control[^]


这篇关于如何创建数字文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆