代码:
//rows 是从数据库中取出来的
//NodeID是定义在数据库中的一个字段。
function callback(r) {
var rows = r.value.Rows;
var tb = document.getElementById('gv1');
var tr,td;
while (tb.rows.length > 1) tb.deleteRow(1); //删除除了页头的行
for (var i = 0; i <= rows.length; i++) {
//tr = tb.insertRow(tb.rows.length);
tr = tb.insertRow(i+1);
td = tr.insertCell(0); td.innerHTML = rows[i].NodeID;
td = tr.insertCell(1); td.innerHTML = rows[i].Role;
td = tr.insertCell(2); td.innerHTML = rows[i].Seq;
td = tr.insertCell(3); td.innerHTML = rows[i].SensorType;
td = tr.insertCell(4); td.innerHTML = rows[i].Area;
td = tr.insertCell(5); td.innerHTML = rows[i].AreaID;
td = tr.insertCell(6); td.innerHTML = rows[i].Power;
td = tr.insertCell(7); td.innerHTML = rows[i].LastActiveTime;
td = tr.insertCell(8); td.innerHTML = rows[i].Hops;
}
}
<form id="Form1" name="form1" method="post" runat="server">
<div align="center">
<asp:GridView runat="server" ID="gv1" CellPadding="4" ForeColor="#333333"
Font-Size="8pt" AllowSorting="True"
onsorting="gv1_Sorting">
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White"
Font-Size="9pt" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
</form>
<script type="text/javascript">
window.setInterval("reload()",2000);
function reload() {
NodeList.GridViewSource(callback);
}
function callback(r) {
var rows = r.value.Rows;
var tb = document.getElementById('gv1');
var tr,td;
while (tb.rows.length > 1) tb.deleteRow(1);
for (var i = 0; i <= rows.length; i++) {
//tr = tb.insertRow(tb.rows.length);
tr = tb.insertRow(i+1);
td = tr.insertCell(0); td.innerHTML = rows[i].NodeID;
td = tr.insertCell(1); td.innerHTML = rows[i].Role;
td = tr.insertCell(2); td.innerHTML = rows[i].Seq;
td = tr.insertCell(3); td.innerHTML = rows[i].SensorType;
td = tr.insertCell(4); td.innerHTML = rows[i].Area;
td = tr.insertCell(5); td.innerHTML = rows[i].AreaID;
td = tr.insertCell(6); td.innerHTML = rows[i].Power;
td = tr.insertCell(7); td.innerHTML = rows[i].LastActiveTime;
td = tr.insertCell(8); td.innerHTML = rows[i].Hops;
}
}
</script>
<form id="Form1" name="form1" method="post" runat="server">
<div align="center">
<asp:GridView runat="server" ID="gv1" CellPadding="4" ForeColor="#333333"
Font-Size="8pt" AllowSorting="True"
onsorting="gv1_Sorting">
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White"
Font-Size="9pt" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
</form>
</body>
tr = tb.insertRow(i+1); 先搞清楚insertrow()function ,含有表头的。