Hi Bittu,
Please refer below Sample.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<table id="tbl1">
<thead>
<tr>
<th style="font-size: smaller;">SN</th>
<th style="font-size: smaller;">Freight</th>
</tr>
</thead>
<tbody>
<asp:Repeater runat="server" ID="rptDetails">
<ItemTemplate>
<tr>
<td class="text-align-center"><%# (((RepeaterItem)Container).ItemIndex+1).ToString()%> </td>
<td class="text-align-center">
<asp:HiddenField runat="server" ID="hdID" Value='<%# Eval("OrderID") %>' />
<asp:TextBox EnableViewState="true" ID="txtFreight" runat="server" Text='<%# Eval("Freight")%>' />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
</table>
<br />
Grand Total:
<asp:TextBox runat="server" ID="txtTotal" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
CalculateTotal();
$("[Id*=txtFreight]").on("keyup", function () {
CalculateTotal();
});
});
function CalculateTotal() {
var total = 0;
$("[Id*=txtFreight").each(function () {
total += parseFloat($(this).val());
});
if (total >= 100) {
alert("Freight total should be less than 100");
} else {
$("[Id*=txtTotal]").val(total);
}
}
</script>
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindRepeater();
}
}
private void BindRepeater()
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 5 OrderID, CAST(Freight AS NUMERIC(5,2)) Freight FROM Orders", con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
rptDetails.DataSource = dt;
rptDetails.DataBind();
}
}
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindRepeater()
End If
End Sub
Private Sub BindRepeater()
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand("SELECT TOP 5 OrderID, CAST(Freight AS NUMERIC(5,2)) Freight FROM Orders", con)
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Using dt As DataTable = New DataTable()
sda.Fill(dt)
rptDetails.DataSource = dt
rptDetails.DataBind()
End Using
End Using
End Using
End Using
End Sub
Screenshot