问题描述
我的网络表单的范围验证器存在问题。我有六个文本框和三个范围验证器。其中三个文本框是来自数据库的填充数据,另外三个文本框是用于将新数据提交到数据库。发生的事情是当用户登录并单击表单的链接时,它会加载表单并显示错误:
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?
推荐答案
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来自数据库的填充数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!