在后台控制输出数据到前台的某个位置

a.前台:定义数据绑定 <ASP:Label ID="labTable" Text="<%# SetTable() %>" runat="server" />
   后台:拼接数据 Page_Load  中调用: labTable.DataBind();
   //设置动态table,可变的字段添加数据
   
  public   string  SetTable()
    
{      
        
string strTbHead = "<table border='0' cellpadding='0' cellspacing='0' width='100%' height='100%'>";
        
string strTbTail = "</table>";
        
string strTbBody = "";
        
string[,] aryTbValue = new string[203];    //aryTbValue[0,0]:名字,aryTbValue[0,1]控件名,aryTbValue[0,2]类型
        for(int i = 0; i < aryTbValue.GetLength(0); i++{
            aryTbValue[i, 
0= "名字"+i;
            aryTbValue[i, 
1= "name"+i;
            aryTbValue[i, 
2= "nvarchar";
        }

        
//列数和行数
        int columnCount = 2;
        
int rowCount = ((aryTbValue.GetLength(0% columnCount) == 0? (aryTbValue.GetLength(0/ columnCount) : (aryTbValue.GetLength(0/ columnCount) + 1;
        
int index = 0;
        
for(int i=0; i<rowCount; i++){
            strTbBody 
+= "<tr height='20'>";
            
for(int j = 0; j < columnCount && index < aryTbValue.GetLength(0); j++{
                
switch(aryTbValue[index, 2]) {
                    
case "nvarchar":
                        strTbBody 
+= "<td align='right' width='20%'>" + aryTbValue[index, 0+ "</td>";
                        strTbBody 
+= "<td align='right' width='20%'><input  type='text' name='" + aryTbValue[index, 1+ "'/></td>";
                        
break;
                }

                index
++;
            }

            strTbBody 
+= "</tr>";
        }

        
return strTbHead + strTbBody + strTbTail;
    }

 b.利用控件 <asp:PlaceHolder id="Place" runat="server"/> 再创建HtmlTable table = new HtmlTable(); Place.Controls.Add(table);  //添加到控件
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值