RangeValidator来自数据库的填充数据的问题 [英] RangeValidator Issue with populated data from database

查看:89
本文介绍了RangeValidator来自数据库的填充数据的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网络表单的范围验证器存在问题。我有六个文本框和三个范围验证器。其中三个文本框是来自数据库的填充数据,另外三个文本框是用于将新数据提交到数据库。发生的事情是当用户登录并单击表单的链接时,它会加载表单并显示错误:

I have an issue with a rangevalidator of my web form. I have six textboxes and three rangevalidators. Three of the textboxes are populated data from the database and the other three textboxes are for new data to be submitted to the database. What is happening is when the user is logged on and clicks the link to the form it loads the form with an error:

"The value '385.2' of the MaximumValue property of 'RangeValidator1' cannot be converted to type 'Integer'.".

从数据库加载的值是321.我试图找出新数字是否比旧数字低20%或高20%(来自数据库)。



这是我的RangeValidator代码:

The value that is loading from the database is 321. I am trying to find out if the new number is 20% lower or 20% higher than the old number (from database).

Here is my code for the RangeValidator:

double txtVal = Convert.ToDouble(TextBox1.Text);
        double minVal = (txtVal * 0.8);
        double maxVal = (txtVal * 1.2);
        RangeValidator1.MinimumValue = minVal.ToString();
        RangeValidator1.MaximumValue = maxVal.ToString();







<asp:RangeValidator ID="RangeValidator1" runat="server" 

                    ControlToValidate="TextBox1" CssClass="style40" 

                    ErrorMessage="20% Difference. Please verify numbers" ForeColor="Red" 

                    Type="Integer" Enabled="True" Display="Dynamic"></asp:RangeValidator>





有没有办法纠正这个问题,仍然可以获得RangeValidator正常工作所需的值?



Is there a way to correct this and still get the value I need for the RangeValidator to work correctly?

推荐答案

验证器类型和值集需要匹配,请看这里 http://msdn.microsoft.com/en-us/ library / 85y3x2a2(v = vs.110).aspx [ ^ ]



public enum ValidationDataType

ValidationDataType枚举代表不同CompareValidator和RangeValidator控件可以验证的数据类型。



因此,要么改变Type =Double,要么将double转换为int
The validator Type and Value set need to match, look here http://msdn.microsoft.com/en-us/library/85y3x2a2(v=vs.110).aspx[^]

public enum ValidationDataType
The ValidationDataType enumeration represents the different data types that the CompareValidator and RangeValidator controls can validate.

So, either change Type="Double" or cast the double to an int


我使用了它并且它可以工作。

I have used this and it works.
int itxtVal11 = Convert.ToInt32(TextBox1.Text);
        int iminVal11 = (itxtVal11 - itxtVal11 * 20 / 100);
        int imaxVal11 = (itxtVal11 + itxtVal11 * 20 / 100);
        RangeValidatorLYTNNCC.MinimumValue = iminVal11.ToString();
        RangeValidatorLYTNNCC.MaximumValue = imaxVal11.ToString();


这篇关于RangeValidator来自数据库的填充数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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