对 ASP.Net 中 GridView 中的 TextBox 的 JavaScript 验证

问题描述:

我有一个 GridView,其中模板字段中有四个文本框.我在 GridView 下方有一个按钮.

I have a GridView in Which I have four TextBoxes in the Template Field. I have one Button below the GridView.

如何验证 GridView 中的 TextBoxes,当按钮被点击时?

How to validate the TextBoxes in the GridView, When the Button Clicked?

使用RequiredFieldValidator并设置ValidationGroup="gridview",查看下面的例子

use RequiredFieldValidator and set ValidationGroup="gridview", check below example

   <asp:TemplateField HeaderText="">
          <ItemTemplate>
              <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
               <asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="TextBox3" ValidationGroup="gridview" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
          </ItemTemplate>
            </asp:TemplateField>
          <asp:TemplateField HeaderText="">
                <ItemTemplate>
                    <asp:Button ID="Button2" runat="server" Text="Button" ValidationGroup="gridview" CausesValidation="true" />
                </ItemTemplate>
            </asp:TemplateField>