acadenilla
asked on
GridView Validation
hi
I have a gridview with two columns that contain a textbox each that i would like to validate. Each row also contains an imagebutton that does some action. How do i make it so that it only validates for the specific row that the button was click?
Allan
I have a gridview with two columns that contain a textbox each that i would like to validate. Each row also contains an imagebutton that does some action. How do i make it so that it only validates for the specific row that the button was click?
Allan
<asp:GridView ID="gvPossibleAnswers" EnableViewState="true" AutoGenerateColumns="false" runat="server" OnRowCreated="gvPossibleAnswers_RowCreated" OnRowDataBound="gvPossibleAnswers_RowDataBound">
<Columns>
<asp:BoundField HeaderText="Option ID" DataField="OptionID" />
<asp:TemplateField HeaderText="Label Text">
<ItemTemplate>
<asp:TextBox ID="txtOptionText" runat="server" Text=""></asp:TextBox>
<asp:RequiredFieldValidator id="rfvOptionText" ControlToValidate="txtOptionText" ErrorMessage="Answer Text is missing" Display="none" runat="server"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sort Order">
<ItemTemplate>
<asp:TextBox ID="txtSortOrder" runat="server" Text=""></asp:TextBox>
<asp:RegularExpressionValidator ID="revSortOrder" ControlToValidate="txtSortOrder" runat="server" ErrorMessage="Sort Order must be a digit" Display="none" ValidationExpression="^\d+$"></asp:RegularExpressionValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:DropDownList EnableViewState="true" ID="ddlStatusInd" runat="server">
<asp:ListItem Value="0S1" Text="Active" />
<asp:ListItem Value="0S0" Text="InActive" />
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Actions">
<ItemTemplate>
<asp:ImageButton ID="imgBtnAdd" runat="server" ImageUrl="~/Images/Delete.gif" OnClick="imgBtnAdd_Click" />
<asp:ImageButton ID="imgBtnEdit" runat="server" ImageUrl="~/Images/Edit.gif" OnClick="imgBtnEdit_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Note i had to dynamically add ValidationSummary controls for each row in for the validation to show the error message.
ASKER
i got it work with your suggestion