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
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
When Good HTML Goes Bad: How You Can Protect Your Web Applications
Many .NET teams are underperforming, is yours?