Reputation: 21
I have a text box in grid view control,i used required field validator to validate the textbox like
<asp:TemplateField HeaderText="Relationship" ItemStyle-Width="15%">
<ItemTemplate>
<asp:TextBox ID="txtRelationShip" runat="server" Text='<%# Eval("RelationShip") %>' Visible="false" autocomplete="off"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvRelationShip" runat="server" ControlToValidate="txtRelationShip" ForeColor="Red" ClientIDMode="AutoID"
ErrorMessage="Please enter relationship" ValidationGroup="vgUpdateRelationShip" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:LinkButton ID="btnRelationShipUpdate" runat="server" ValidationGroup="vgUpdateRelationShip"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
I have many rows in my grid view , when i edit and update the text box value if single text box is empty it shows error in all text box. How to resolve this problem, i want if single text box is empty shows error only in single text box
Upvotes: 0
Views: 903
Reputation: 35554
You have to make sure that the ValidationGroup
is unique per row, like ValidationGroup='<%# "ValidationGroup_" + Container.DataItemIndex %>'
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"
ControlToValidate="TextBox1" ValidationGroup='<%# "ValidationGroup_" + Container.DataItemIndex %>'></asp:RequiredFieldValidator>
<asp:LinkButton ID="LinkButton1" runat="server" ValidationGroup='<%# "ValidationGroup_" + Container.DataItemIndex %>'>Update</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
Upvotes: 1