海军资料

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

      这是我刚接触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>

posted on 2007-02-03 23:25  周海军  阅读(7360)  评论(0编辑  收藏  举报