How to use compare validator with a set of different values?
Q:
I have a gridview contains a textbox as a template field :
the aspx:
<asp:GridView Width="100%" ID="gv_Evaluation" CssClass="datatable" AllowSorting="True"
runat="server" AutoGenerateColumns="False" AllowPaging="True" GridLines="None"
OnRowDataBound="gv_Evaluation_RowDataBound"&g开发者_如何学运维t;
<Columns>
<asp:TemplateField HeaderText="serial">
<ItemTemplate>
<asp:Label ID="lblSerial" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="activity type" DataField="activityType" />
<asp:BoundField HeaderText="weight" DataField="activityWeight" />
<asp:TemplateField HeaderText="evaluation">
<ItemTemplate>
<telerik:RadTextBox ID="txt_evaluateWeights" runat="server" AutoPostBack="True"
OnTextChanged="txt_evaluateWeights_TextChanged"></telerik:RadTextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txt_evaluateWeights" Display="Dynamic" ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle VerticalAlign="Top" CssClass="row" />
</asp:GridView>
the weight column contains the following numbers[50,10,10,10,5,5,10]
What I wanna to do is:
Validate the data entry when the user enters the data in the txt_evaluateWeights
Where it must be less than or equal the meeting one in the weight
column. I do that in server side. But I wanna to do that client side. I tried to use the compare validator but it doesn't suit my case because each time i compare with a different value, according to the weight column.
You can use the CustomValidator
class and set the ClientValidationFunction
property to use clientside validation
see MSDN documentation
精彩评论