Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
A table having 5 rows and 3 columns,
each row contain 3 asp.net server controls textbox for userinput.

i want to dynamically add more rows in table on buttonclick while each new row contain 3 textboxes for user input.

i am not expert of client side, currently i am doing static work by hiding rows (10 extra rows) and displaying them one by one on button click, but this is not efficent work and also have limitations.

Thankx in Advance.

Zain Ul Abedin
Posted

1 solution

Try this simple HTML and JavaScript code. Hope it may help you to resolve your problem.

HTML
<html>
  <HEAD>
	<script type="text/javascript">
		function insRow() {
			var tbl = document.getElementById('myTable');
			var len = tbl.rows.length;
			var row = tbl.insertRow(len);
			for(var i  = 0; i < tbl.rows[0].cells.length-1; i++) {
				row.insertCell(i).innerHTML="<input type=text>";
			}
			row.insertCell(tbl.rows[0].cells.length-1).innerHTML='<INPUT TYPE="button" ONCLICK="delRow(this)" VALUE="Delete Row">';
		}

		function delRow(obj) {
			var row = obj;
			while(row.nodeName.toLowerCase() != 'tr') {
				row = row.parentNode;
			}
			var tbl = document.getElementById('myTable');
			tbl.deleteRow(row.rowIndex);

		}
	</script>
  </HEAD>
  <BODY>
    <table id="myTable" border="1" width="50%" cellspacing="0" cellpadding="2">
      <tr>
	<td>cell 1</td>
	<td>cell 2</td>
	<td>cell 3</td>
	<td><INPUT TYPE="button" ONCLICK="insRow()" VALUE="Insert Row"></td>
      </tr>
    </table><br>
    <FORM>


    </FORM>
  </BODY>
</HTML>
</br></html>


Thanks & Regards,
Niral Soni
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900