Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
Questions & Answers
Tips & Tricks
 how to compare values in gridview columns using compare validator
Posted by charan on  4/5/2010 3:47:58 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend

hi iam using with c# with ajax

when user enters the quantity value it should not be greater than current quantity

<asp:TemplateField HeaderText="CurrentQTY" SortExpression="CurrentQTY">
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("CurrentQTY") %>'></asp:TextBox>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("CurrentQTY") %>'></asp:Label>

<asp:TemplateField HeaderText="Quantity" >

<ItemTemplate ><asp:TextBox ID="txtqty" runat="server" AutoPostBack="true" OnTextChanged="CalculateValues"></asp:TextBox><asp:CompareValidator ID="cmp" runat="server" ControlToCompare="TextBox3" ControlToValidate="txtqty" Type="Double" Operator="LessThanEqual" ErrorMessage="Quantity Shouldless than CurrentQuantity">*</asp:CompareValidator><cc1:ValidatorCalloutExtender ID="vvcomp" runat="server" TargetControlID="cmp"></cc1:ValidatorCalloutExtender></ItemTemplate>

when iam using this to compare than it is giving error that textbox3 is not find by compare validator

can you give example which helps me

Post Your Reply Post New Question

 Viewer's Reply
Compare Validator inside GridView
Answered By Moderator1 on 4/5/2010 8:40:50 AM

I found your TextBox3 is in EditItemTemplate and CompareValidator is in ItemTemplate. So while rendering the CompareValidator cannot find the TextBox3. One of the solution is to use the ValueToCompare property of the CompareValidator. Bind this value in design time.
Other option is to place use RangeValidator and set its Maximum Value as value of Current Qty through code-behind. Place the Rangevalidator in ItemTemplate section.
Post Your Reply If you still have problem, post it again under this reply for better response.

Sponsored by
Easing the Migration to Microsoft SQL Server 2005
When Good HTML Goes Bad: How You Can Protect Your Web Applications
Simply JavaScript - Free 150 Page Preview!