Click here to Skip to main content
15,940,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to set required field in footer template,while adding records working fine but while updating already existing record ,that time also validation working ,so i cant update mt data.

What I have tried:

 <asp:TextBox ID="txtpname" runat="server"></asp:TextBox>
            <asp:DropDownList ID = "ddlprice1" runat = "server">
            <asp:Button ID="btnAdd" CommandName="AddNew" runat="server" Text="Add"></asp:Button><br />
            <asp:RequiredFieldValidator runat="server" id="reqName" controltovalidate="txtpname" errormessage="Please enter product name!" />
            <asp:RequiredFieldValidator ID="reqPrice" runat="server" ControlToValidate="ddlprice1" 
                            InitialValue="0" ErrorMessage="Select Price"></asp:RequiredFieldValidator>

Updated 6-Mar-17 2:11am

1 solution

refer this example

<!DOCTYPE html>

<html xmlns="">
<head runat="server">

<script src=""></script>

        function checkMandaory(obj) {

            var row = obj.parentElement.parentElement;
            var name = $('input[id*="txtName"]', row).val();
            var address = $('input[id*="txtAddress"]', row).val();
            if (row == '' || address == '') {
                alert('Please enter the Mandatory fields!');
                return false;
            return true;


    <form id="form1" runat="server">

        <asp:GridView ID="GridView1" runat="server" Width="550px" AutoGenerateColumns="false"
            AlternatingRowStyle-BackColor="#C2D69B" HeaderStyle-BackColor="green" ShowFooter="true">
                <asp:TemplateField HeaderText=" Name">
                        <%# Eval("Name") %>
                        <asp:TextBox ID="txtName" runat="server" />
                <asp:TemplateField HeaderText="Address">
                        <%# Eval("Address") %>
                        <asp:TextBox ID="txtAddress" runat="server" />

                        <asp:Button ID="btnAdd" OnClientClick="return checkMandaory(this)" runat="server" Text="Add" OnClick="Button1_Click" CommandName="Footer" />
            <AlternatingRowStyle BackColor="#C2D69B" />


protected void Page_Load(object sender, EventArgs e)
           if (!Page.IsPostBack)
               DataTable dt = new DataTable();
               dt.Rows.Add("aa", "aa-1");
               dt.Rows.Add("bb", "bb-1");
               dt.Rows.Add("cc", "cc-1");
               dt.Rows.Add("dd", "dd-1");
               GridView1.DataSource = dt;


       protected void Button1_Click(object sender, EventArgs e)

Share this answer
GrpSMK 6-Mar-17 9:10am    
Thank You for Your Ans:-)
Karthik_Mahalingam 6-Mar-17 9:17am    
welcome :)

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