Wafaa
Wafaa

Reputation:

Validate Gridview

I have gridview with template fields(textbox,dropdown list,...) and I use required field validators for the textbox and dropdownlist where I make the validation on textchanged and dropselected index changed my problem is that the validation happend on all rows not just on the row where i change the text any idea?

validation is going to be fired for all dropdowns residing into other rows. how can i orevent this?

thanks

this the code:

 <asp:GridView ID="uxCountSheetView" runat="server" AutoGenerateColumns="false" OnRowDataBound="uxCountSheetView_RowDataBound"
             AllowPaging="true" PageSize="15" OnPageIndexChanging="uxCountSheetView_PageIndexChanging" ShowFooter="true">
            <Columns>

            <asp:TemplateField HeaderText="Item">
            <ItemTemplate>
            <asp:DropDownList ID="uxItems" runat="server" Width="100" CausesValidation="true" ValidationGroup="All" AutoPostBack="true" OnSelectedIndexChanged="uxItems_SelectedIndexChanged"></asp:DropDownList>
            <asp:RequiredFieldValidator id="RequiredFieldValidator3"
          ControlToValidate="uxItems" Display="Static" ValidationGroup="All" InitialValue="" Width="100%" runat="server">*</asp:RequiredFieldValidator>          </ItemTemplate> </asp:TemplateField>
<asp:TemplateField HeaderText="AfterQuantity">
            <ItemTemplate>
            <asp:TextBox ID="uxAfterQuantity" ValidationGroup="All" CausesValidation="true" OnTextChanged="uxAfterQuantity_TextChanged" AutoPostBack="true" runat="server"></asp:TextBox>
           <cc1:FilteredTextBoxExtender ID="uxFilterAfterQuantity" runat="server" FilterType="Custom, Numbers"
             TargetControlID="uxAfterQuantity" ValidChars="."></cc1:FilteredTextBoxExtender>
               <asp:RequiredFieldValidator runat="server" id="RequiredFieldValidator6"></asp:RequiredFieldValidator>
          ControlToValidate="uxAfterQuantity"
          Display="Static" ValidationGroup="All"
          InitialValue="" Width="100%" runat="server"></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="Difference"></Columns></asp:GridView>

Upvotes: 1

Views: 3594

Answers (2)

coder
coder

Reputation: 11

check this link to validate controls in gridview with a validator

http://www.opexsolution.com/category/technical-corner/

go to Using Validators in gridview control Part I topic

Upvotes: 1

Canavar
Canavar

Reputation: 48088

If you postback your form when a row selected, you can set your currentrow's validator controls' ValidationGroup to an active text, and all other validation controls at other rows should have ValidationGroup inactive.

And also set your submit button's ValidationGroup to active text that causes validation.

This will allow your submit button to validate only validators with the active ValidationGroup.

Upvotes: 1

Related Questions