View Single Post
  #7 (permalink)  
Old April 5th, 2010, 12:32 PM
ysfkay ysfkay is offline
Authorized User
Points: 343, Level: 6
Points: 343, Level: 6 Points: 343, Level: 6 Points: 343, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2009
Posts: 74
Thanks: 5
Thanked 0 Times in 0 Posts
Default I need some help here, thansks...

The code u wrote works,

I have now tried to apply it to create a html table dynamically using the array values as the html table data.

But the problem is in the C# for loops, where I use the c# outer and inner for loops' control variables i and j to index

the javascripts' DOM table methods.

When I click the button that calls the javascript method "n()", I get the

run time error "object expected", and this part of the button declaration is highlited "onclick="n();" "

I'd appreciate some explanation if possible, thanks.

here is the portion of my default.aspx.cs page
//////////////////////




//U may skip the following 6 lines of javascript-DOM that create the table and the table body

sb.Append("function n(){");

sb.Append("var oTable=document.createElement('table');");

sb.Append("oTable.setAttribute('border','1');");

sb.Append("oTable.setAttribute('width','100%');");

sb.Append("var oTBody=document.createElement('tbody');");

sb.Append("oTable.appendChild(oTBody);");

////////////////////
//this is the problem area

int x=0;

int[] r = { 1, 2, 3, 4, 5, 6,7,8,9,10 };

for (int i = 0; i < 5; i++)
{
sb.Append("oTBody.insertRow("+i+");");

for (int j = 0; j < 2; j++)
{

sb.Append("oTBody.rows["+i+"].insertCell("+j+");");


sb.Append(" oTBody.rows[" + i + "].cells[" + j + "].appendChild(document.createTextNode(" + r[x] + "]));");

sb.Append(" document.body.appendChild(oTable);");

++x;
}
}
sb.Append("}");

cs.RegisterClientScriptBlock(t, s2, sb.ToString(), true);