Karthik_Mahalingam
см. этот пример
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<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;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" Width="550px" AutoGenerateColumns="false"
AlternatingRowStyle-BackColor="#C2D69B" HeaderStyle-BackColor="green" ShowFooter="true">
<Columns>
<asp:TemplateField HeaderText=" Name">
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtName" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemTemplate>
<%# Eval("Address") %>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtAddress" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnAdd" OnClientClick="return checkMandaory(this)" runat="server" Text="Add" OnClick="Button1_Click" CommandName="Footer" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="#C2D69B" />
</asp:GridView>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Address");
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;
GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}