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>

  • 相关阅读:
    join
    runlevel 运行级别
    腾讯一shell试题.
    awk grep sed 的一些问题
    while read line do done < file
    awk 中 RS,ORS,FS,OFS 区别与联系
    节选
    rpm -qa -qc 查询安装过的软件
    css实现两端对齐
    JS表单验证
  • 原文地址:https://www.cnblogs.com/ziyan22/p/639230.html
Copyright © 2011-2022 走看看