Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Requirement:
Appending two rows dynamically in a existing table.

Step 1: Initially table contains no rows.

A button named as AddField .
For each button click repeat the following step.

Step 2: two rows added to the table.

How it is possible using javascript.

Please provide a solution in asp.net mvc3.

MyCode:
JavaScript
$('#Field tr').length;//first i take the current number of tr. 
Here 'Field' is my table id.
then using the following code i append one row below the current row.
 $('.AddTableRowForm').append(//Inside this i specified all controls which are added on each row.)

Ouput:
appended one row with specified controls.

Actual Output:
Append two rows below the current row.

Thanks& Regards,
Anupama
Posted
v3
Comments
Maciej Los 5-Aug-13 2:54am    
What have you done so far? Where are you stuck?
AnupamaPillai 5-Aug-13 4:27am    
currently i take count of 'tr' and dynamically adding one row on each button click. But my actual requirement is adding two rows on each button click. Is it possible ??
Maciej Los 5-Aug-13 4:33am    
If it is possible to add one row, then two is possible too ;)
AnupamaPillai 5-Aug-13 5:23am    
No. at a time one row is appended.
Maciej Los 5-Aug-13 5:25am    
Please, share your code. Use "Improve question" widget. Shortly describe your issue.

1 solution

The append statement you are using appends a row to the table. So as many times you write that statement it will append that many rows to your table.
Since in your case you 2 such rows, just write the append statement two times:
$('.AddTableRowForm').append(//Inside this i specified all controls which are added on each row.)
In case the number of appends are large, you could use a for loop to make the code shorter.
 
Share this answer
 
Comments
Ankur\m/ 5-Aug-13 7:54am    
Btw that was very trivial. I hope you are learning and not coding for some client.

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