机考题库软件 您好,欢迎来到南京精略教育软件有限公司!免费服务热线:400-080-5550

首页 > 行业动态 > Asp.net后台创建HTML

Asp.net后台创建HTML


a)         为了使HTML界面中的内容能根据数据库中的内容动态显示用户需要的内容,或者根据权限不同要显示同而实现页面内容的动态创建

2.内容:

          a)      使用HtmlGenericControl创建HTML标签

          引入命名空间: using System.Web.UI.HtmlControls;

          更改其属性: hgg_div.Attributes.Add("style","width:200px; height:200px;");

          内容设置: hgg_div.InnerText = "我是一个" + htmlTag;(htmlTag可以是div,br,span…)

   或者InnerHtml来给div写一些html

  b)         使用Table newTable = new Table();创建表格控件

  newTable.Width = 200;设置高

  newTable.Height = 200; 设置宽

  创建行: TableRow newTableRow = new TableRow();

  newTableRow.Height = 20;

         创建单元格: TableCell newTableCell = new TableCell();

                      newTableCell.Width = 100;

            newTableCell.Text = "我是一个单元格";

                   添加到表格中: newTableRow.Controls.Add(newTableCell);

                         newTableRow.Controls.Add(newTableCell);

                         newTable.Controls.Add(newTableRow);

 

  1. 将创建的标签或者控件添加到页面中

  Page.Controls.Add(newTable);//添加到表单外(control)

  Page.Form.InnerHtml=str;//添加到表单内(html) 

发布时间:2012-10-10 13:24:47

分享到: