var rowNum = 0,filenum = 0; Line number and column number
var Onewrow; Defining Insert Row Objects
var onewcell1,onewcell2; Defining Insert Column Objects
var filenum = 1;
function addfiletotable (strfile)
{
FileNum +=1;
RowNum = document.getElementById ("Newfilelist"). Rows.length;
Onewrow = document.getElementById ("Newfilelist"). InsertRow (RowNum);
Onewrow.id = "Clientrow_" + filenum;
Add first column
ONEWCELL1 = document.getElementById ("Newfilelist"). Rows[rownum].insertcell (0);
onewcell1.innerhtml = "<input type= ' Text ' readonly= ' readonly ' style= ' border:0px;width:100px; ' value= '" + GetFileName (strfile) + "'/>";
Add second column
ONewCell2 = document.getElementById ("Newfilelist"). Rows[rownum].insertcell (1);
onewcell2.innerhtml = "<span name=" + filenum + "style=" cursor:hand;color:red; Text-decoration:none; Font-family: @HGP????? E; ' onclick= ' delclientrow (this); ' >X</span> ';
}
Asp. NET background code how to manipulate HTML table
Example 1: The method is to read all the files on the server's "strFilePath" folder and display it in the table with the id "oldfilelist" on the page, note that the table "Runat=server".
public void Showfilesin (String strFilePath)
{
OldFileList.Rows.Clear ();
string[] Strfilenames = Getfilesinserver (strFilePath);
for (int i = 0; i < strfilenames.length; i++)
{
HtmlTableRow NewRow = new HtmlTableRow ();
Newrow.id = "Serverrow_" + i;
HtmlTableCell cell1 = new HtmlTableCell ();
HtmlTableCell cell2 = new HtmlTableCell ();
Cell1. InnerHtml = "<input type= ' Text ' readonly= ' readonly ' style= ' border:0px;width:90px; ' value= '" + strfilenames[i] + "'/&G t; ";
Cell2. InnerHtml = "<span name=" + strfilenames[i] + "style=" cursor:hand;color:red; Text-decoration:none; Font-family: @HGP????? E; ' onclick= ' delserverrow (this); ' >X</span> ';
NEWROW.CELLS.ADD (CELL1);
NEWROW.CELLS.ADD (CELL2);
OLDFILELIST.ROWS.ADD (NewRow);
}
}
JavaScript background code How to manipulate HTML table