Hi sthsyed,
Check with the below code.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$(document).on('click', '#btnAddPlate', function () {
var trs = $('[id*=gvPlate]').closest('tr:not(":has(th)")');
$(trs).each(function () {
if ($(this).find('[id*=chkRow]')[0].checked) {
var plate = $(this).find("[id*=txtEnterPlate]").val().trim();
var customerName = $(this).find("[id*=txtCustomerName]").val().trim();
var custMobile = $(this).find("[id*=txtCustMobile]").val().trim();
var civilId = $(this).find("[id*=txtCivilId]").val().trim();
var deposit = $(this).find("[id*=txtDeposit]").val().trim();
if (plate == "" || customerName == "" || custMobile == "" || civilId == "" || deposit == "") {
alert("Required");
return false;
}
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvPlate" runat="server" Font-Names="Times New Roman" Font-Size="Small"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" runat="server" Checked="true" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkRow" runat="server" Checked="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Resrv_Id" HeaderText="Resrv Id" />
<asp:BoundField DataField="Vin" HeaderText="Vin" />
<asp:BoundField DataField="ResDate" HeaderText="Resrv Date" />
<asp:BoundField DataField="Model Code" HeaderText="Model Code" />
<asp:BoundField DataField="Model Year" HeaderText="Model Year" />
<asp:BoundField DataField="Model No_" HeaderText="Model No" />
<asp:BoundField DataField="Color" HeaderText="Color" />
<asp:BoundField DataField="Location" HeaderText="Location" />
<asp:BoundField DataField="Status" HeaderText="Status" />
<asp:BoundField DataField="Plate" HeaderText="Plate" />
<asp:BoundField DataField="Stock_Type" HeaderText="Stock Type" />
<asp:TemplateField HeaderText="Plate">
<ItemTemplate>
<asp:TextBox ID="txtEnterPlate" runat="server" Text='<%# Eval("Plate") %>' Width="75" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cust Name">
<ItemTemplate>
<asp:TextBox ID="txtCustomerName" runat="server" Text='<%# Eval("Customer_Name") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact No">
<ItemTemplate>
<asp:TextBox ID="txtCustMobile" runat="server" Text='<%# Eval("CustMobileNo") %>'
MaxLength="8" Width="80" CssClass="tmob" />
<asp:RegularExpressionValidator ID="MobileValidator" runat="server" ControlToValidate="txtCustMobile"
ErrorMessage="Should be no" ForeColor="Red" ValidationExpression="^[0-9]+$" Font-Size="Smaller"></asp:RegularExpressionValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Civil Id">
<ItemTemplate>
<asp:TextBox ID="txtCivilId" runat="server" Text='<%# Eval("CustCivilId") %>' MaxLength="12"
Width="110" />
<asp:RegularExpressionValidator ID="CivilIdValidator" runat="server" ControlToValidate="txtCivilId"
ErrorMessage="Should be no" ForeColor="Red" ValidationExpression="^[0-9]+$" Font-Size="Smaller"></asp:RegularExpressionValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Deposit">
<ItemTemplate>
<asp:TextBox ID="txtDeposit" runat="server" Text='<%# Eval("CustDeposit") %>' MaxLength="12"
Width="100" />
<asp:RegularExpressionValidator ID="DepositValidator" runat="server" ControlToValidate="txtDeposit"
ErrorMessage="Should be no" ForeColor="Red" ValidationExpression="^[0-9 .]+$"
Font-Size="Smaller"></asp:RegularExpressionValidator>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Button ID="btnAddPlate" Text="Add Plate" runat="server" />
</div>
</form>
</body>
</html>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("Resrv_Id", typeof(int)),
new DataColumn("Vin"),
new DataColumn("ResDate"),
new DataColumn("Model Code"),
new DataColumn("Model Year"),
new DataColumn("Model No_"),
new DataColumn("Color"),
new DataColumn("Location"),
new DataColumn("Status"),
new DataColumn("Plate"),
new DataColumn("Stock_Type"),
new DataColumn("Customer_Name"),
new DataColumn("CustMobileNo"),
new DataColumn("CustCivilId"),
new DataColumn("CustDeposit")
});
dt.Rows.Add(1, "Vin1", "ResDate1", "1", "2011", "1", "Red", "Andheri", "1", "Plate1", "Type1", "Mudassar", "1111", "11", "1200");
dt.Rows.Add(2, "Vin2", "ResDate2", "2", "2012", "2", "Blue", "Bandra", "0", "Plate2", "Type2", "Maria", "2222", "12", "1300");
dt.Rows.Add(3, "Vin3", "ResDate3", "3", "2013", "3", "Yellow", "Malad", "0", "Plate3", "Type3", "John", "3333", "13", "1400");
dt.Rows.Add(4, "Vin4", "ResDate4", "4", "2014", "4", "Green", "Powai", "1", "Plate4", "Type4", "Crejesh", "4444", "14", "1500");
gvPlate.DataSource = dt;
gvPlate.DataBind();
}
}