Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Guys,

I have to create a table or div based on database rows count.
Suppose, 20 rows are there on database. So 2 div or td should be created dynamically.
If 25 rows are available on database then 3 div or td should be created dynamically.
and table rows should be shown on div or td.

Actually i am opening a popup window using window.open method and it has link button. On click of link button either i have to open another popup window and create a table or division tag based on database table rows or on the same popup window i have to create the div or table itself and based on no. of divs window size should be resized.

What I have tried:

I am wondering how to do this on popup window based on database table rows count.
Posted
Updated 9-Jan-18 0:03am
Comments
Karthik_Mahalingam 6-Jan-18 6:18am    
post the code what you have tried.
Kornfeld Eliyahu Peter 7-Jan-18 6:06am    
Search for JavaScript templates...

1 solution

For create table dynamically use can use following method:

- Create one label in your popup window i.e. lblData
- On your button click write following code:
JavaScript
var sTableData = '';
	var iRow = 0;
	sTableData = '<table>';
	for(iRow=0;iRow<=tablerowcount;iRow++)
	{
		sTableData = sTableData + '<tr><td>specify data you want show</td</tr>';
	}
	sTableData = sTableData + '</table>;

	document.getElementById('lblData').innerHTML = sTableData;

Hope it will be helpful.
 
Share this answer
 
Comments
Member 11052432 9-Jan-18 23:37pm    
Hi my requirement is like I have to create div based on database rows count.
if 5 rows are there on db, then 1 div will be created.
if 20 rows are there on db, then 2 div will be created.
if 25 rows are there on db, then 3 div will be created.
if 56 rows are there on db, then 3 div will be created.

Please provide the logic.
Rajesh Pandya 10-Jan-18 1:11am    
You can use above logic just remove the for loop and use if condition like below:
if(tablerowcount = 5)
{ sTableData = 'specify data you want show'; }
else if(tablerowcount = 20)
{ sTableData = 'specify data you want show';
sTableData = sTableData + 'specify data you want show';
}
Like above add as many condition as required for create div based on row count.

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