在GridView内部需要字段验证不起作用 [英] Inside GridView required Field validation is not working
本文介绍了在GridView内部需要字段验证不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<asp:GridView ID="GrdHiringResource" runat="server" AutoGenerateColumns="False" DataKeyNames="hiring_resource_id"
OnRowCancelingEdit="GrdHiringResource_RowCancelingEdit" OnRowDataBound="GrdHiringResource_RowDataBound"
OnRowEditing="GrdHiringResource_RowEditing"
OnRowUpdating="GrdHiringResource_RowUpdating" OnRowCommand="GrdHiringResource_RowCommand"
ShowFooter="True" OnRowDeleting="GrdHiringResource_RowDeleting"
BackColor="White" BorderColor="#D1B271" BorderStyle="None" BorderWidth="1px"
CellPadding="4">
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" BorderColor="#D1B271" />
<RowStyle BackColor="White" ForeColor="#000000" BorderColor="#D1B271"/>
<Columns>
<asp:TemplateField HeaderText="Hiring Resource name" SortExpression="Location_name">
<EditItemTemplate>
<asp:TextBox ID="txtName" runat="server" Text='<%# Eval("hiring_resource_name") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtName" ErrorMessage="Please enter ResourceName">*</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="ReqNewname" runat="server" ControlToValidate="txtNewName" ErrorMessage="Please enter ResourceName">*</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("hiring_resource_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<EditItemTemplate>
<asp:TextBox ID="txtdescription" runat="server" Text='<%# Bind("description") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewdescription" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="" ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="true" CommandName="AddNew"
Text="Add New"></asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="" ShowDeleteButton="True" ShowHeader="True" />
</Columns>
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" BorderColor="#D1B271" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" BorderColor="#D1B271" />
<HeaderStyle BackColor="#D1B271" Font-Bold="True" ForeColor="#000000" HorizontalAlign="Center" BorderColor="#D1B271"/>
</asp:GridView>
在我们添加新条目的页脚部分中,所需的字段验证器不起作用,当我们编辑它时冲突
In this in footer part when we add new entry then required field validator is not working and when we edit then it conflict
推荐答案
HI,
为两个requiredfieldvalidtor和相应的链接按钮添加不同的验证组.. < br $> b $ b
赞
Add different validation group for two requiredfieldvalidtor and to respective linkbuttons..
like
<asp:TemplateField HeaderText="Hiring Resource name" SortExpression="Location_name">
<EditItemTemplate>
<asp:TextBox ID="txtName" runat="server" Text='<%# Eval("hiring_resource_name") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ValidationGroup="update" runat="server" ControlToValidate="txtName" ErrorMessage="Please enter ResourceName">*</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="ReqNewname" runat="server" ValidationGroup="save"ControlToValidate="txtNewName" ErrorMessage="Please enter ResourceName">*</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("hiring_resource_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
和
and
<asp:TemplateField HeaderText="" ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" ValidationGroup="update"
Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="true" CommandName="AddNew" va
Text="Add New"></asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
快乐编码....
happy coding ....
plz查看此链接,可能有帮助。
[ ^ ]
plz check this link ,may be it helpfull.
[^]
这篇关于在GridView内部需要字段验证不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文