0

如何在按钮单击时对 RangeValidator1 进行硬编码,以根据所查看产品的特定类型执行不同的操作,例如:

if(id == 1)
{
RangeValidator1.Enabled = true;
RangeValidator1.Type = ValidationDataType.Integer;
RangeValidator1.MaximumValue = "6";
RangeValidator1.MinimumValue = "1";
RangeValidator1.ErrorMessage = "Only 6 allowed per customer";
}
else if(id == 2)
{
RangeValidator1.Enabled = true;
RangeValidator1.Type = ValidationDataType.Integer;
RangeValidator1.MaximumValue = "10";
RangeValidator1.MinimumValue = "1";
RangeValidator1.ErrorMessage = "Only 10 allowed per customer";
}
else
RangeValidator.Enabled = false;

这是我想要在单击按钮时实现的一般要点,但它引发了关于“无法将 MaximumValue 属性 RangeValidator1 的值”转换为 Integer 类型的错误。

帮助?

4

1 回答 1

0

RangeValidator1.MaximumValue 需要像你这样的字符串值

RangeValidator1.MaximumValue = "10";

要使其从整数变量中获取,请将 .ToString() 添加到此变量中,如下所示

    int x = 10;
    RangeValidator1.MaximumValue = x.ToString();
于 2013-08-22T21:25:26.163 回答