I have never worked on jquery but after some googling and learning I have been able to use it in my application. I am trying to update a table row in my asp.net project but I am not able to update the table row by setting .html of it with the new data which I am receiving through a service.
I am prepopulating the table in the code behind so to generate the row and coloumns and also apply cssclass labels according to one of the ID. The ultimately render htmml of the table on the browser is as follows:
<table id="dataTable">
<tr class="Row1">
<td>CC</td><td>0</td><td>0</td><td>0</td><td>1</td>
</tr>
<tr class="Row2">
<td>CC</td><td>0</td><td>0</td><td>0</td><td>2</td>
</tr>
<tr class="Row3">
<td>CC</td><td>0</td><td>0</td><td>0</td><td>3</td>
</tr>
</table>
The code of my asp page through which I am trying to update the data row is as follows:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_Default" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<title>Simple AJAX Service Client Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Table ID="dataTable" runat="server" />
</form>
<script type="text/javascript" src='<%= ResolveUrl("~/Scripts/jquery-1.4.1.js") %>' ></script>
<script src="~/scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
jQuery.ajaxSetup({
// Disable caching of AJAX responses
cache: false
});
$(document).ready(function () { setTimeout("countdown()", 1000); });
function countdown() {
$.getJSON("http://localhost:8732/Service/GetStat", null, function (result) {
for (var key = 0, size = result.length; key < size; key++) {
var htmlstr =
'<td>'
+ result[key].Name
+ '</td><td>'
+ result[key].Size
+ '</td><td>'
+ result[key].Count
+ '</td><td>'
+ result[key].Handle
+ '</td><td>'
+ result[key].ID
+ '</td>';
$('.Row' + result[key].ID).html = htmlstr //id values are like 1, 2, 3.....
}
});
setTimeout("countdown()", 1000);
};
</script>
</body>
</html>
When I debug the code using Visual studio by putting the break point the value of the html that being formulated is in proper order (one of the sample value is as follows <td>CC</td><td>18444289</td><td>6</td><td>248</td><td>1</td>) and the variable value when debugging for (‘.Row’ + result[key].MonitorID) is like ROW1 and so on….
So why when setting the .html of this not working for me. Any help much appreciated.
Thank you.
Try using
.emptyand.append, something like this: