JavaScript后台代码操作HTML TABLE的方法

本文展示了如何使用ASP.NET在HTML表格中添加、显示文件信息,并提供了后台代码实现,包括读取服务器文件夹内的文件名并将其显示在表格中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

var rowNum = 0,fileNum = 0; //行号与列号 
var oNewRow; //定义插入行对象 
var oNewCell1,oNewCell2; //定义插入列对象 
var fileNum = 1; 

function addFileToTable(strFile) 

fileNum +=1; 
rowNum = document.getElementById("NewFileList").rows.length; 
oNewRow = document.getElementById("NewFileList").insertRow(rowNum); 
oNewRow.id = "clientRow_" + fileNum; 

//添加第一列 
oNewCell1 = document.getElementById("NewFileList").rows[rowNum].insertCell(0); 
oNewCell1.innerHTML = "<input type='Text' readonly='readonly' style='border:0px;width:100px;' value='" + getFileName(strFile) + "' />"; 

//添加第二列 
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后台代码操作HTML TABLE的方法  

例1:该方法是读取服务器上路经为"strFilePath"的文件夹中的所有文件,并显示在页面上ID为"OldFileList"的TABLE中,注意,这个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] + "' />"; 
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); 

}

转载于:https://www.cnblogs.com/ranran/p/4081770.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值