zoukankan      html  css  js  c++  java
  • 动态的创建Table(Asp.net中)

          这是我刚接触Asp.Net不久的时候,有一个项目中有产品展示功能.自己以前是用asp来完成这样的功能的.当接到这样的任务时,自己不知道在Asp.Net中如何来实现此功能.后来就在别人的指点下用手动创建Table 的方法来实现.后来又还了DataList来实现了.

    例一
       

    string name = "dfdfs";
    HtmlTable tab_mid1 = new HtmlTable();
    HtmlTableRow tr = new HtmlTableRow();
    HtmlTableCell tc = new HtmlTableCell();
    tc.Width="34%";
    tc.InnerHtml="<a href=\"#\"><strong><font color=\"#336633\">"+name+"</font></strong></a>";
    tr.Cells.Add(tc);
    tab_mid1.Rows.Add(tr);
    Page.Controls.Add(tab_mid1);
    例二.
    <script runat="server" language="C#">
      void Page_Load()
      {
      //create a new HTMLTable object
      HtmlTable table1 = new HtmlTable();
      HtmlTableRow row;
      HtmlTableCell cell;
      
      //set the table's styles
      table1.Border =1;
      table1.CellPadding =3;
      table1.CellSpacing =3;
      table1.BorderColor ="red";
      for(int i=1; i<=5; i++)
      {
      //create a new row and set its background color
      row = new HtmlTableRow();
      row.BgColor =(i%2==0 ?"lightyellow" : "lightcyan");
      
      for(int j=1; j<=4; j++)
      {
      //create a cell and set its text
      cell = new HtmlTableCell();
      cell.InnerHtml ="Row :" + i.ToString()+
      "<br>Cell:"+j.ToString();
      
      //add the cell to the current row
      row.Cells.Add(cell);
      }
      
      //add the row to the table
      table1.Rows.Add(row);
      }
      
      //add the table to page
      Page.Controls.Add(table1);
      
      }
      </script>

  • 相关阅读:
    AcWing 276. I-区域
    学习笔记:可持久化线段树(主席树):静态 + 动态
    NOIP2016提高组 天天爱跑步
    AcWing 195. 骑士精神
    标准文档流
    css 盒模型
    css 继承性和层叠性
    css 选择器
    css 引入方式
    html body中的标签2
  • 原文地址:https://www.cnblogs.com/ziyan22/p/639230.html
Copyright © 2011-2022 走看看