简体   繁体   English

限制文本框中的整数范围

[英]Limit the integer range in textbox

I put Text-box in grid-view and Bind that text-box value to data-table value. 我将“文本框”放在网格视图中,然后将该文本框值绑定到数据表值。 When there is 0 integer then text-box is not shown, and when value greater than 0 that specific value is shown in text box. 当整数为0时,则不显示文本框;当值大于0时,该特定值显示在文本框中。

ASP CODE: ASP代码:

<ItemTemplate>
    <asp:TextBox ID="txtQuantity" Text='<%# Bind("InStock_Quantity") %>' Style="text-align: right;" onfocus="this.select()"runat="server" OnTextChanged="OnTextChange" Visible='<%# Convert.ToBoolean(Eval("InStock_Quantity")) %>'  AutoPostBack="true" ></asp:TextBox>

    <asp:RequiredFieldValidator ID="rfv_txtQuantity" ControlToValidate="txtQuantity"
 ErrorMessage="enter quantity in order grid " InitialValue='<%# Bind("InStock_Quantity") %>' Text="*" ValidationGroup="form" runat="server"></asp:RequiredFieldValidator>
</ItemTemplate>

在此处输入图片说明

I want if user write more then that value show in text-box the message will display "Quantity enter is greater than available quantity!" 我想如果用户写的更多,然后该值显示在文本框中,则消息将显示“输入的数量大于可用数量!” and value must be restricted to value <= that value like "90". 并且值必须限制为值<=该值,例如“ 90”。

Javascript is good then how could I do??? Javascript好,那我该怎么办???

In ASP.NET you can use the Range Validator and set a min and max. 在ASP.NET中,可以使用范围验证器并设置最小值和最大值。 For example: 例如:

<asp:RangeValidator ID="RangeValidator1" runat="server" Type="Integer" ControlToValidate="txtQuantity" MaximumValue="90" MinimumValue="1"
 ValidationGroup="form" ForeColor="Red" ErrorMessage="Must be equal or less than 90" />

try this, it maybe helpful to you 试试这个,可能对您有帮助

<asp:CompareValidator runat="server" Operator="DataTypeCheck" Type="Integer" 
ControlToValidate="ValueTextBox" ErrorMessage="Value must be a whole number" />

<asp:RangeValidator runat="server" Type="Integer" 
MinimumValue="0" MaximumValue="400" ControlToValidate="ValueTextBox" 
ErrorMessage="Value must be a whole number between 0 and 400" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM