动态添加表格

first drop a table typeof webcontrol
<asp:Table id="tbl" runat=server />

then
<script language="c#">
void Page_Load(object sender, System.EventArgs e)
{
for(int i=0;i<hs;i++)
{
  TableCell tc = new TableCell();
  tc.Width = Unit.Percent(16);
  tc.HorizontalAlign = HorizontalAlign.Center;
  tc.VerticalAlign =VerticalAlign.Top;
  tc.Height = Unit.Pixel(71);
  tbl.Rows.Add(new TableRow());
  tbl.Rows[Rows.Count-1].Cells.Add(tc);
}
}
</script>

下面是基于javascript

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 2</title>
</head>

<body>
<script>
var j=0
function add_row(){
    j=sqd.rows.length;
    newRow=document.all.sqd.insertRow(-1)
    newcell=newRow.insertCell()
    newcell.style.backgroundColor='#f7f7f7'
    newcell.innerHTML=j
    newcell=newRow.insertCell()
    newcell.style.backgroundColor='#f7f7f7'
    newcell.innerHTML="<input name=SerialNumber type=radio value="+j+">"
    newcell=newRow.insertCell()
    newcell.style.backgroundColor='#f7f7f7'
    newcell.innerHTML="<input name=SerialNumber1 type=text class=INPUT1 size=3>"
    newcell=newRow.insertCell()
    newcell.style.backgroundColor='#f7f7f7'
    newcell.innerHTML="<input name=ProductName type=text class=INPUT1 size=3>"
    newcell=newRow.insertCell()
    newcell.style.backgroundColor='#f7f7f7'
    newcell.innerHTML="<input name=jianshu type=text class=INPUT1 size=3>"
    newcell=newRow.insertCell()
    newcell.style.backgroundColor='#f7f7f7'
    newcell.innerHTML="<input name=Quantity type=text class=INPUT1 size=3>"
    newcell=newRow.insertCell()
    newcell.style.backgroundColor='#f7f7f7'
    newcell.innerHTML="<input name=GrossWeight type=text class=INPUT1 size=3>"
    newcell=newRow.insertCell()
    newcell.style.backgroundColor='#f7f7f7'
    newcell.innerHTML="<input name=CountWeight type=text class=INPUT1 size=3>"
    newcell=newRow.insertCell()
    newcell.style.backgroundColor='#f7f7f7'
    newcell.innerHTML="<input name=UnitPrice type=text class=INPUT1 size=3>"
    newcell=newRow.insertCell()
    newcell.style.backgroundColor='#f7f7f7'
    newcell.innerHTML="<input name=Amount type=text class=INPUT1 size=3>"
    newcell=newRow.insertCell()
    newcell.style.backgroundColor='#f7f7f7'
    newcell.innerHTML="<input name=CustOrder type=text class=INPUT1 size=3>"
    newcell=newRow.insertCell()
    newcell.style.backgroundColor='#f7f7f7'
    newcell.innerHTML="<input name=Discription type=text class=INPUT1 size=3>"
}
function del_row() {
    if(sqd.rows.length==1) return;
    var checkit = false
    for (var i=0;i<document.all.SerialNumber.length;i++) {
        if (document.all.SerialNumber[i].checked) {
        checkit=true;
        sqd.deleteRow(i+1)
        break;
        }
    }
    if (checkit) {return true} else {alert("please select one");return false}
    
}
function re(){
for (p=1;p<sqd.getElementsByTagName('tr').length;p++){
sqd.getElementsByTagName('tr')[p].getElementsByTagName('td')[0].innerText=p;}
}
</script>
<table id="sqd" width="90%" border="0" cellpadding="0" cellspacing="1" bgcolor="#999999">
<tr bgcolor="#BAC2DA">
<td height="25"> <div align="center">序号</div></td>
<td> <div align="center">选中</div></td>
<td> <div align="center">货物编号</div></td>
<td> <div align="center">货物品名</div></td>
<td> <div align="center">件数</div></td>
<td> <div align="center">数量</div></td>
<td> <div align="center">毛重</div></td>
<td> <div align="center">计货重量</div></td>
<td> <div align="center">费率</div></td>
<td> <div align="center">金额</div></td>
<td> <div align="center">客户定单号</div></td>
<td> <div align="center">备注</div></td>
</tr>
</table>
<br> <input name="Submit5" type="button" onClick=add_row() class="button" value=" 添 加 ">
<input name="Submit33" οnclick=del_row();re() type="button" class="button" value=" 删 除 ">
</body>

</html>
[/html]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值