Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
C#
<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
Posted
Comments
Herman<T>.Instance 16-Feb-12 4:07am    
conflict with what? Please show exception

HI,

Add different validation group for two requiredfieldvalidtor and to respective linkbuttons..

like
XML
<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

XML
<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 ....
 
Share this answer
 
plz check this link ,may be it helpfull.

[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900