Hey RumeValid,
Please refer below sample.
HTML
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('input[type=text]').on('keyup', function () {
var trs = $(this).closest('tr');
var tds = trs.find('td');
var acco = $(tds).find('[id*=txtaccomod]').val() != "" ? $(tds).find('[id*=txtaccomod]').val() : "0";
var trans = $(tds).find('[id*=txttranspot]').val() != "" ? $(tds).find('[id*=txttranspot]').val() : "0";
var feeding = $(tds).find('[id*=txtfeeding]').val() != "" ? $(tds).find('[id*=txtfeeding]').val() : "0";
var ot = $(tds).find('[id*=txtothercst]').val() != "" ? $(tds).find('[id*=txtothercst]').val() : "0";
$(tds).find('[id*=txttotcst]').val(parseInt(acco) + parseInt(trans) + parseInt(feeding) + parseInt(ot));
});
});
</script>
<div>
<asp:Label ID="lblText" runat="server" />
</div>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
string strTR = "<table>";
for (int i = 0; i < 5; i++)
{
strTR = strTR + "<tr>"
+ "<td> " + " <span>" + (i + 1).ToString() + "</span> " + "</td>"
+ "<td> " + " <input name='txtaccomod' type='text' id='txtaccomod" + (i + 1).ToString().Trim() + "' class='txtaccomod' style='width:100px;' /> " + "</td>"
+ "<td> " + " <input name='txttranspot' type='text' id='txttranspot" + (i + 1).ToString().Trim() + "' class='txttranspot' style='width:100px;' /> " + "</td>"
+ "<td> " + " <input name='txtfeeding' type='text' id='txtfeeding" + (i + 1).ToString().Trim() + "' class='txtfeeding' style='width:100px;' /> " + "</td>"
+ "<td> " + " <input name='txtothercst' type='text' id='txtothercst" + (i + 1).ToString().Trim() + "' class='txtothercst' style='width:100px;' /> " + "</td>"
+ "<td> " + " <input name='txttotcst' type='text' id='txttotcst" + (i + 1).ToString().Trim() + "' class='txttotcst' style='width:100px;' /> " + "</td>"
+ "</tr>";
}
lblText.Text = strTR + "</table>";
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim strTR As String = "<table>"
For i As Integer = 0 To 5 - 1
strTR = strTR & "<tr>" & "<td> " & " <span>" & (i + 1).ToString() & "</span> " & "</td>" & "<td> " & " <input name='txtaccomod' type='text' id='txtaccomod" & (i + 1).ToString().Trim() & "' class='txtaccomod' style='width:100px;' /> " & "</td>" & "<td> " & " <input name='txttranspot' type='text' id='txttranspot" & (i + 1).ToString().Trim() & "' class='txttranspot' style='width:100px;' /> " & "</td>" & "<td> " & " <input name='txtfeeding' type='text' id='txtfeeding" & (i + 1).ToString().Trim() & "' class='txtfeeding' style='width:100px;' /> " & "</td>" & "<td> " & " <input name='txtothercst' type='text' id='txtothercst" & (i + 1).ToString().Trim() & "' class='txtothercst' style='width:100px;' /> " & "</td>" & "<td> " & " <input name='txttotcst' type='text' id='txttotcst" & (i + 1).ToString().Trim() & "' class='txttotcst' style='width:100px;' /> " & "</td>" & "</tr>"
Next
lblText.Text = strTR & "</table>"
End Sub
Screenshot
