Hi smile,
Please refer below sample.
HTML
<div>
Total :
<asp:TextBox ID="txtTotal" runat="server" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="AdmissionNo" HeaderText="Reg No." />
<asp:BoundField DataField="ReferenceNo" HeaderText="Ref No." />
<asp:BoundField DataField="SName" HeaderText="Student Name" />
<asp:BoundField DataField="FName" HeaderText="Father Name" />
<asp:BoundField DataField="FPhone" HeaderText="Phone No." />
<asp:BoundField DataField="SubjectName" HeaderText="Subject" />
<asp:TemplateField>
<HeaderTemplate>
Obtain</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtObtain" runat="server" Text="0"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('[id*=txtObtain]').on("blur", function () {
var totalMarks = $("#txtTotal").val();
if (parseInt($(this).val()) > parseInt(totalMarks)) {
alert('Obtain Marks should be less than Total Marks');
$(this).val('');
$(this).focus();
}
});
});
</script>
Namespace
C#
using System.Data;
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("AdmissionNo", typeof(string)),
new DataColumn("ReferenceNo", typeof(string)),
new DataColumn("SName", typeof(string)),
new DataColumn("FName", typeof(string)),
new DataColumn("FPhone", typeof(string)),
new DataColumn("SubjectName", typeof(string)) });
dt.Rows.Add("A1", "R1", "SN1", "FN1", "123344556", "English");
dt.Rows.Add("A2", "R2", "SN2", "FN2", "222222154", "Maths");
dt.Rows.Add("A3", "R3", "SN3", "FN3", "565656656", "Hindi");
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
}
Screenshot