asp.net前端验证 - 只允许更低的值

时间:2011-09-07 08:11:20

标签: asp.net visual-studio validation gridview frontend

我正在编辑gridview中的一个字段,并希望编辑后的值不允许大于旧值?

是否有前端验证?以免使用javascript弹出窗口

由于

<asp:TemplateField HeaderText="FC Amount">             
    <ItemTemplate>   
        <asp:Label ID="FCLabel" runat="server" Text='<%# Eval("FC AMOUNT") %>'></asp:Label>         
    </ItemTemplate>
    <EditItemTemplate>                    
        <asp:TextBox ID="FCTextBox1" runat="server" Text='<%# Eval("FC AMOUNT") %>'></asp:TextBox>
    </EditItemTemplate>
</asp:TemplateField> 

2 个答案:

答案 0 :(得分:1)

使用CompareValidator控件:

使用旧值添加隐藏,并将其值与新值进行比较。或者设置ValueToCompare属性:

<asp:TemplateField HeaderText="FC Amount">             
    <ItemTemplate>   
        <asp:Label ID="FCLabel" runat="server" Text='<%# Eval("FC AMOUNT") %>'></asp:Label>         
    </ItemTemplate>
    <EditItemTemplate>                    
        <asp:TextBox ID="FCTextBox1" runat="server" Text='<%# Eval("FC AMOUNT") %>'></asp:TextBox>
        <asp:CompareValidator 
    ID="cmpAmount" 
    runat="server" 
    ValueToCompare='<%# Eval("FC AMOUNT") %>'
    ControlToValidate="FCTextBox1"
    Type="Double"
    Operator="LessThanEqual" /> 

    </EditItemTemplate>
</asp:TemplateField>

How to: Validate Against a Specific Value for ASP.NET Server Controls
CompareValidator.Operator Property

答案 1 :(得分:1)

试试这个,

 <asp:CompareValidator 
        ID="cval1" 
        runat="server" 
        ValueToCompare='<%#Eval("OldValue") %>'
        ControlToValidate="FCTextBox1"
        Type="Integer"
        Operator="GreaterThanEqual" />