我正在编辑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>
答案 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" />