title: How to get jquery data validator to work with Asp.net gridview
body: <p>I've been trying to implement the jquery validator that is the suggested answer here: <a href="https://stackoverflow.com/questions/619816/jquery-validation-plugin-in-asp-net-web-forms">jQuery Validation plugin in ASP.NET Web Forms</a></p>
  
  <p>but in this and every other example I've found it requires that the elements to be validated are in a form. This may be a newbie question, but I have an asp:textbox (rather than an input) inside an asp:gridview and I can't get the validation to work. Is there a way to nest some of this in a form or do one of these asp functions generate a form automatically in html?</p>
  
  <p>If it helps, here is the jquery code I'm using and my gridview:</p>
  
  <pre><code> &lt;script type = "text/javascript"&gt;
   $(function() {     
   // You can specify some validation options here but not rules and messages
        $('form').validate();
        // Add a custom class to your name mangled input and add rules like this     
        $('textbox[id$=NPI]').rules('add', {
            required: true,
            messages: {
                required: 'Some custom message for the username required field'
            }
         });
         }); 
      &lt;/script&gt;
  
   &lt;div style="overflow:auto; height:300px;"&gt;
  &lt;asp:GridView ID="SetRules" runat="server" AutoGenerateColumns="False" DataSourceID="AttributesRules" OnDataBound="Anchor_Changed"
      class="styleGrid archGrid validation" AlternatingRowStyle-CssClass = "styleGridAlt" DataKeyNames="banner, pricinggroupkey, attribute, tieranchor, tierother"&gt;
      &lt;Columns&gt;                                               
      &lt;asp:TemplateField HeaderText="New Price Index" SortExpression="NewPriceIndex"&gt;               
              &lt;ItemTemplate&gt;
                  &lt;asp:TextBox ID="NPI" class="NumVal" runat="server" 
                      Text='&lt;%# Bind("NewPriceIndex", "{0:N2}") %&gt;'&gt;&lt;/asp:TextBox&gt;
              &lt;/ItemTemplate&gt;  
          &lt;/asp:TemplateField&gt;
  
      &lt;asp:TemplateField HeaderText="New Index Range" SortExpression="NewIndexRange"&gt;               
              &lt;ItemTemplate&gt;
                  &lt;asp:TextBox ID="NIR" class="NumVal" runat="server" 
                      Text='&lt;%# Bind("NewIndexRange", "{0:N2}") %&gt;'&gt;&lt;/asp:TextBox&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;           
                  &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  &lt;/div&gt;
  </code></pre>