如何在gridbox中使用comparevalidator和gridview中的boundfield项

时间:2018-03-05 11:52:38

标签: c# asp.net ajax gridview

您好我有一个名为“OrderedQty”的asp绑定域和一个asp文本框(txtDeliveredQty)的gridview,其中用户输入已交付数量的数量。如何使用comparevalidator来阻止用户输入低于OrderedQty的数字(整数)的验证?

以下是我使用此过滤优先级的代码:

<asp:BoundField DataField="Qty" HeaderText="Ordered" SortExpression="Qty"></asp:BoundField>
                            <asp:TemplateField HeaderText="Delivered Qty">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtNewQty" runat="server" CssClass="form-control" Width="100" TextMode="Number" Min="1"></asp:TextBox>
                                    <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Please enter a valid number" ControlToValidate="txtNewQty" MinimumValue="1" MaximumValue="100" SetFocusOnError="true" Type="Integer"></asp:RangeValidator>
                                </ItemTemplate>
                            </asp:TemplateField>

谢谢!

1 个答案:

答案 0 :(得分:1)

您需要在范围验证器上添加Control To Compare

<asp:RangeValidator ID="RangeValidator1" runat="server" 
ControlToValidate="txtDeliveredQty" 
ControlToCompare="OrderedQty" Operator="LessThan" Type="Integer" 
ErrorMessage="The first number should be smaller than the second number!"  
Type="Integer"></asp:RangeValidator>