DotNet Academy of Rajesh Rolen

Solutions by Rajesh Rolen

Add/delete rows in HTML Table at run time using javascript

< script language="javascript" type="text/javascript" >

function addrow()
{
var tbody = document.getElementById("< %= tableName.ClientID % >").getElementsByTagName("TBODY")[0];
var row = document.createElement("TR")
var td1 = document.createElement("TD")
var td2 = document.createElement("TD")
var td3 = document.createElement("TD")

td1.appendChild(document.createTextNode("value"));
td2.appendChild(document.createTextNode("value));

//to add hyper liked cell for delete row
var code = "< a href=\'#\' onClick=\"javascript:deleteCriteria(this.parentNode.parentNode.rowIndex);\" >< img src=\"Images/user_delete.png\" alt=\"Delete\" / >< /a >";

td3.setAttribute("align", "center");
td3.innerHTML = code;

row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);

tbody.appendChild(row);
}

function deleteCriteria(i) {
if (window.confirm('Are you sure you want to delete this record?') == true) {
document.getElementById("< %= tblcriteria.ClientID % >").deleteRow(i);

}
}
< /script >

0 comments:

Post a Comment

About this blog

My Blog List

Advertise On This Site

Site Info

Advertise on this Site

To advertise on this site please mail on RajeshRolen@gmail.com

Information Source

About

Pages

Dot Net Academy

Advertis in This Area of Site

Powered by Blogger.

Followers

Search This Blog