Usage
Take a hidden control on the webpage ("hdhidden") and set its default value to 1 and runat = server. 1 is added to its value when a new row is added in a table but does not change when a row is deleted from the table. Following are the two functions which perform addition and deletion of rows in a table.
<script language="javascript">
function deleteTableRows()
{
var counts=parseInt(document.all("hdhidden").value);
var i;
var a=0;
for(i=1;i<counts;i++)
{
itemCheck="chk_"+i;
if(document.all[itemCheck]!=undefined)
{
a = a + 1;
if(document.all[itemCheck].checked==true)
{
if(a!=i)
{
tblvalue.deleteRow(a);
}
else
{
tblvalue.deleteRow(i);
}
i = parseInt(i) - 1;
a = a - 1;
}
}
}
return false;
}
function AddItem()
{
var counts=parseInt(document.all("hdhidden").value);
var Row,Cell;
var CurrentPosition=parseInt(counts);
Row = window.tblvalue.insertRow();
Cell = Row.insertCell();
Cell.innerHTML="<input type=checkbox name=chk_" +
CurrentPosition +" id=chkbox_"+ CurrentPosition+"; value='C'>";
Cell = Row.insertCell();
Cell.innerHTML="<input style=Font-size=11; type=Text name=txtval1_"
+ CurrentPosition +" id=txtval1_"+ CurrentPosition+>";
//insert another cell in a row
Cell = Row.insertCell();
//insert a textbox in a cell with the name
//"txtval2_" as prefix + its current position
Cell.innerHTML="<input style=Font-size=11; type=Text name=txtval2_" +
CurrentPosition +" id=txtval2_"+ CurrentPosition+>";
document.all("hdhidden").value = parseInt(counts) + 1;
return false;
}
</script>
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here