在网格视图中不需要验证错误警报

时间:2014-03-12 09:55:26

标签: asp.net validation gridview

我有一个网格视图,用于编辑和插入数据。 1)为了插入数据我使用页脚行。 2)和编辑数据我使用其余的行。  问题是,当我试图在网格视图中更新任何行时,页脚行验证也会获得警报,我不想要...我希望只有选定的行验证应保持活动...

enter image description here

我的网格视图代码是:

 <asp:GridView ID="PanelDetGridView" CssClass="table col-12 table-bordered table-hover widget-box widget-title widget-content nopadding" runat="server" AutoGenerateColumns="false" ShowFooter="true" OnRowCancelingEdit="PanelDetGridView_RowCancelingEdit" OnRowCommand="PanelDetGridView_RowCommand" OnRowDeleting="PanelDetGridView_RowDeleting" OnRowEditing="PanelDetGridView_RowEditing" OnRowUpdated="PanelDetGridView_RowUpdated" OnRowUpdating="PanelDetGridView_RowUpdating">
                                <Columns>
                                    <asp:TemplateField HeaderText="Make">
                                        <ItemTemplate>
                                            <%# Eval("DevManufcture.Name") %>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <asp:DropDownList ID="DDLManfct" AutoPostBack="true" OnSelectedIndexChanged="DDLManfct_SelectedIndexChanged" DataSourceID="SqlDataSourceForManufctPanel" DataTextField="Name" DataValueField="idDeviceManufacturer" runat="server"></asp:DropDownList>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" CssClass="help-inline" Font-Size="Small" runat="server" ErrorMessage="*Required" ControlToValidate="DDLManfct"></asp:RequiredFieldValidator>
                                        </EditItemTemplate>
                                        <FooterTemplate>
                                            <asp:DropDownList ID="DDLInsertManfct" AutoPostBack="true" OnSelectedIndexChanged="DDLInsertManfct_SelectedIndexChanged" DataSourceID="SqlDataSourceForManufctPanel" DataTextField="Name" DataValueField="idDeviceManufacturer" runat="server"></asp:DropDownList>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" CssClass="help-inline" Font-Size="Small" runat="server" ErrorMessage="*Required" ControlToValidate="DDLInsertManfct"></asp:RequiredFieldValidator>
                                        </FooterTemplate>
                                    </asp:TemplateField>

                                    <asp:TemplateField HeaderText="Model">
                                        <ItemTemplate>
                                            <%# Eval("DevModel.Name") %>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <asp:DropDownList ID="DDLModel" AutoPostBack="true" OnSelectedIndexChanged="DDLModel_SelectedIndexChanged" runat="server"></asp:DropDownList>
                                         <asp:RequiredFieldValidator ID="RequiredFieldValidator3" CssClass="help-inline" Font-Size="Small" runat="server" ErrorMessage="*Required" ControlToValidate="DDLModel"></asp:RequiredFieldValidator>
                                        </EditItemTemplate>
                                        <FooterTemplate>
                                            <asp:DropDownList ID="DDLInsertModel" AutoPostBack="true" OnSelectedIndexChanged="DDLInsertModel_SelectedIndexChanged" runat="server"></asp:DropDownList>
                                         <asp:RequiredFieldValidator ID="RequiredFieldValidator4" CssClass="help-inline" Font-Size="Small" runat="server" ErrorMessage="*Required" ControlToValidate="DDLInsertModel"></asp:RequiredFieldValidator>
                                        </FooterTemplate>
                                    </asp:TemplateField>

                                    <asp:TemplateField HeaderText="Type">
                                        <ItemTemplate>
                                            <%# Eval("DevMoType.Name") %>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <asp:DropDownList ID="DDLType" AutoPostBack="true" OnSelectedIndexChanged="DDLType_SelectedIndexChanged" runat="server"></asp:DropDownList>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator5" CssClass="help-inline" Font-Size="Small" runat="server" ErrorMessage="*Required" ControlToValidate="DDLType"></asp:RequiredFieldValidator>
                                        </EditItemTemplate>
                                        <FooterTemplate>
                                            <asp:DropDownList ID="DDLInsertType" AutoPostBack="true" OnSelectedIndexChanged="DDLInsertType_SelectedIndexChanged" runat="server"></asp:DropDownList>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator6" CssClass="help-inline" Font-Size="Small" runat="server" ErrorMessage="*Required" ControlToValidate="DDLInsertType"></asp:RequiredFieldValidator>
                                        </FooterTemplate>
                                    </asp:TemplateField>



                                    <asp:TemplateField HeaderText="Power">
                                        <ItemTemplate>
                                            <%# Eval("Power") %>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <asp:TextBox ID="txtpwr"   Text='<%# Eval("Power") %>' runat="server" CssClass="form-control" Font-Size="Small" Height="20px" Width="200px"></asp:TextBox>
                                         <asp:RequiredFieldValidator ID="RequiredFieldValidator7" CssClass="help-inline" Font-Size="Small" runat="server" ErrorMessage="*Required" ControlToValidate="txtpwr"></asp:RequiredFieldValidator>
                                         <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="  Enter Numbers Only ..." ValidationExpression="^[1-9]\d*(\.\d+)?$" ControlToValidate="txtpwr" CssClass="help-inline" Font-Size="Small"></asp:RegularExpressionValidator>
                                        </EditItemTemplate>
                                        <FooterTemplate>
                                            <asp:TextBox ID="Instxtpwr" runat="server" CssClass="form-control" Font-Size="Small" Height="20px" Width="200px"></asp:TextBox>
                                         <asp:RequiredFieldValidator ID="RequiredFieldValidator8" CssClass="help-inline" Font-Size="Small" runat="server" ErrorMessage="*Required" ControlToValidate="Instxtpwr"></asp:RequiredFieldValidator>
                                         <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="  Enter Numbers Only ..." ValidationExpression="^[1-9]\d*(\.\d+)?$" ControlToValidate="Instxtpwr" CssClass="help-inline" Font-Size="Small"></asp:RegularExpressionValidator>
                                        </FooterTemplate>
                                    </asp:TemplateField>

                                    <asp:TemplateField HeaderText="Current">
                                        <ItemTemplate>
                                            <%# Eval("Current") %>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <asp:TextBox ID="txtcurr" Text=' <%# Eval("Current") %>' runat="server" CssClass="form-control" Font-Size="Small" Height="20px" Width="200px"></asp:TextBox>
                                         <asp:RequiredFieldValidator ID="RequiredFieldValidator9" CssClass="help-inline" Font-Size="Small" runat="server" ErrorMessage="*Required" ControlToValidate="txtcurr"></asp:RequiredFieldValidator>
                                         <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage="  Enter Numbers Only ..." ValidationExpression="^[1-9]\d*(\.\d+)?$" ControlToValidate="txtcurr" CssClass="help-inline" Font-Size="Small"></asp:RegularExpressionValidator>
                                        </EditItemTemplate>
                                        <FooterTemplate>
                                            <asp:TextBox ID="Instxtcurr" runat="server" CssClass="form-control" Font-Size="Small" Height="20px" Width="200px"></asp:TextBox>
                                         <asp:RequiredFieldValidator ID="RequiredFieldValidator10" CssClass="help-inline" Font-Size="Small" runat="server" ErrorMessage="*Required" ControlToValidate="Instxtcurr"></asp:RequiredFieldValidator>
                                         <asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ErrorMessage="  Enter Numbers Only ..." ValidationExpression="^[1-9]\d*(\.\d+)?$" ControlToValidate="Instxtcurr" CssClass="help-inline" Font-Size="Small"></asp:RegularExpressionValidator>
                                        </FooterTemplate>
                                    </asp:TemplateField>

                                    <asp:TemplateField HeaderText="Length">
                                        <ItemTemplate>
                                            <%# Eval("Length") %>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <asp:TextBox ID="txtlen"   Text='<%# Eval("Length") %>' runat="server" CssClass="form-control" Font-Size="Small" Height="20px" Width="200px"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator11" CssClass="help-inline" Font-Size="Small" runat="server" ErrorMessage="*Required" ControlToValidate="txtlen"></asp:RequiredFieldValidator>
                                         <asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" ErrorMessage="  Enter Numbers Only ..." ValidationExpression="^[1-9]\d*(\.\d+)?$" ControlToValidate="txtlen" CssClass="help-inline" Font-Size="Small"></asp:RegularExpressionValidator>
                                        </EditItemTemplate>
                                        <FooterTemplate>
                                            <asp:TextBox ID="Instxtlen" runat="server" CssClass="form-control" Font-Size="Small" Height="20px" Width="200px"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator12" CssClass="help-inline" Font-Size="Small" runat="server" ErrorMessage="*Required" ControlToValidate="Instxtlen"></asp:RequiredFieldValidator>
                                         <asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server" ErrorMessage="  Enter Numbers Only ..." ValidationExpression="^[1-9]\d*(\.\d+)?$" ControlToValidate="Instxtlen" CssClass="help-inline" Font-Size="Small"></asp:RegularExpressionValidator>
                                        </FooterTemplate>
                                    </asp:TemplateField>

                                    <asp:TemplateField HeaderText="Width">
                                        <ItemTemplate>
                                            <%# Eval("Width") %>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <asp:TextBox ID="txtWidth" Text=' <%# Eval("Width") %>' runat="server" CssClass="form-control" Font-Size="Small" Height="20px" Width="200px"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator13" CssClass="help-inline" Font-Size="Small" runat="server" ErrorMessage="*Required" ControlToValidate="txtWidth"></asp:RequiredFieldValidator>
                                         <asp:RegularExpressionValidator ID="RegularExpressionValidator7" runat="server" ErrorMessage="  Enter Numbers Only ..." ValidationExpression="^[1-9]\d*(\.\d+)?$" ControlToValidate="txtWidth" CssClass="help-inline" Font-Size="Small"></asp:RegularExpressionValidator>
                                        </EditItemTemplate>
                                        <FooterTemplate>
                                            <asp:TextBox ID="Instxtwidth" runat="server" CssClass="form-control" Font-Size="Small" Height="20px" Width="200px"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator14" CssClass="help-inline" Font-Size="Small" runat="server" ErrorMessage="*Required" ControlToValidate="Instxtwidth"></asp:RequiredFieldValidator>
                                         <asp:RegularExpressionValidator ID="RegularExpressionValidator8" runat="server" ErrorMessage="  Enter Numbers Only ..." ValidationExpression="^[1-9]\d*(\.\d+)?$" ControlToValidate="Instxtwidth" CssClass="help-inline" Font-Size="Small"></asp:RegularExpressionValidator>
                                        </FooterTemplate>
                                    </asp:TemplateField>

                                        <asp:CommandField ButtonType="Button" ShowEditButton="true" />

                        <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ShowHeader="True" />
                        <asp:TemplateField HeaderText="Insert" ShowHeader="False" HeaderStyle-HorizontalAlign="Left">
                            <FooterTemplate>
                                <asp:LinkButton ID="lnkAdd" runat="server" CausesValidation="False" CommandName="Insert" Text="Insert"></asp:LinkButton>
                            </FooterTemplate>
                            </asp:TemplateField>



                                </Columns>
                            </asp:GridView>

1 个答案:

答案 0 :(得分:1)

类似这样的事情

 <asp:RequiredFieldValidator ID="RequiredFieldValidator17" CssClass="error"      ControlToValidate="txtSmalloc" ValidationGroup="CodataValidation" Display="Dynamic" runat="server" ErrorMessage="something" />

 <FooterTemplate>
 <asp:LinkButton ID="lnkAdd" runat="server" CausesValidation="True" ValidationGroup="CodataValidation" CommandName="Insert" Text="Insert"></asp:LinkButton>
 </FooterTemplate>