• .net 自动创建组件并通过操作属性实现页面样式效果


    实现效果:

    aspx页面代码:

     1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="IdiographDispay.aspx.cs" Inherits="idiograph_IdiographDispay" %>
     2 
     3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     4 
     5 <html xmlns="http://www.w3.org/1999/xhtml" >
     6 <head runat="server">
     7     <title>无标题页</title>
     8     <style type="text/css">
     9 .tmd
    10 {
    11     font-size:15px;
    12     position:absolute;
    13 }
    14 .dept
    15 {
    16     font-size:15px;
    17     position:absolute;
    18     color: #FF0000
    19 }
    20 .label
    21 {
    22     font-size:15px;
    23     position:absolute;
    24 }
    25 .labelno
    26 {
    27     font-size:15px;
    28     position:absolute;
    29     color: #FF0000
    30 }
    31 </style>
    32 </head>
    33 <body>
    34     <form id="form1" runat="server">
    35     <div>
    36         <table style=" 279px">
    37             <tr>
    38                 <td style=" 100px">
    39                     <asp:DropDownList ID="ddlDept" runat="server" AutoPostBack="True"  OnSelectedIndexChanged="ddlDept_SelectedIndexChanged">
    40         </asp:DropDownList></td>
    41             </tr>
    42         </table>      
    43         </div>
    44     </form>
    45 </body>
    46 </html>

    cs页面代码:

      1 /// <summary>
      2     /// 获取指定科室的签名信息
      3     /// </summary>
      4     /// <param name="strDept">科室代码</param>
      5     public void Data_Load(string strDept)
      6     {
      7         int row = 1;
      8         DataTable dt = new DataTable();
      9         if (strDept.Length > 0)
     10         {
     11             dt = ((DataTable)ViewState["dtAll"]).Clone();
     12             DataRow[] rows = ((DataTable)ViewState["dtAll"]).Select("dept_code='"+strDept+"'");
     13             for (int i = 0; i < rows.Length; i++)
     14             {
     15                 dt.ImportRow((DataRow)rows[i]);
     16             }
     17         }
     18         else
     19         {
     20             dt = ((DataTable)ViewState["dtAll"]);
     21         }        
     22         bool bDeptColor = true;
     23         for (int i = 0; i < dt.Rows.Count; i++)
     24         {
     25             if (i == 0)
     26             {
     27                 Label lbDeptName = new Label();
     28                 lbDeptName.Text = dt.Rows[i][1].ToString();
     29                 lbDeptName.CssClass = "dept";
     30                 lbDeptName.Style.Add(HtmlTextWriterStyle.Left, "10px");
     31                 int iRowtop = row * 70 + 20;
     32                 string strRowtop = iRowtop.ToString();
     33                 lbDeptName.Style.Add(HtmlTextWriterStyle.Top, strRowtop + "px");
     34                 this.Controls.Add(lbDeptName);
     35                 bDeptColor = true;
     36                 row++;
     37             }
     38             if (!bDeptColor)
     39             {
     40                 Label lbDeptName = new Label();
     41                 lbDeptName.Text = dt.Rows[i][1].ToString();
     42                 lbDeptName.CssClass = "dept";
     43                 lbDeptName.Style.Add(HtmlTextWriterStyle.Left, "10px");
     44                 int iRowtop = row * 70 + 20;
     45                 string strRowtop = iRowtop.ToString();
     46                 lbDeptName.Style.Add(HtmlTextWriterStyle.Top, strRowtop + "px");
     47                 this.Controls.Add(lbDeptName);
     48                 bDeptColor = true;
     49                 row++;
     50             }
     51             for (int j = 0; j < 3;j++ )
     52             {
     53                 int iLeft = (j % 3) * 360;
     54 
     55                 string strLeft = iLeft.ToString();
     56 
     57                 int iLeft0 = iLeft + 10;
     58                 string strLeft0 = iLeft0.ToString();
     59 
     60                 int iLeft2 = iLeft + 60;
     61                 string strLeft2 = iLeft2.ToString();
     62 
     63                 int iLeft3 = iLeft + 135;
     64                 string strLeft3 = iLeft3.ToString();
     65 
     66                 int iTop = row * 70;
     67                 int iTopImage = iTop - 20;
     68                 string strTop = iTop.ToString();
     69                 string strTopImage = iTopImage.ToString();
     70 
     71                 Label lbName = new Label();
     72                 lbName.Text = dt.Rows[i][0].ToString();
     73                 lbName.CssClass = "tmd";
     74                 lbName.Style.Add(HtmlTextWriterStyle.Left, iLeft0 + "px");
     75                 lbName.Style.Add(HtmlTextWriterStyle.Top, strTop + "px");
     76 
     77                 Label lbTitle = new Label();
     78                 lbTitle.Text = dt.Rows[i][2].ToString();
     79                 lbTitle.CssClass = "tmd";
     80                 lbTitle.Style.Add(HtmlTextWriterStyle.Left, iLeft2 + "px");
     81                 lbTitle.Style.Add(HtmlTextWriterStyle.Top, strTop + "px");
     82 
     83                 Image image = new Image();
     84                 image.ImageUrl = "Common/ShowImage.aspx?id=" + dt.Rows[i][3].ToString(); //获取签名
     85                 image.CssClass = "tmd";
     86                 image.Style.Add(HtmlTextWriterStyle.Left, iLeft3 + "px");
     87                 image.Style.Add(HtmlTextWriterStyle.Top, strTopImage + "px");
     88                 image.Style.Add(HtmlTextWriterStyle.Height, HImage + "px");
     89 
     90                 this.Controls.Add(lbName);
     91                 this.Controls.Add(lbTitle);
     92                 this.Controls.Add(image);
     93                 if (i>=dt.Rows.Count-1)
     94                 {
     95                     break;
     96                 }
     97                 if (dt.Rows[i][1].ToString() != dt.Rows[i + 1][1].ToString())
     98                 {
     99                     bDeptColor = false;
    100                     break;
    101                 }
    102                 if (j != 2)
    103                 {
    104                     i++;
    105                 }
    106             }
    107             
    108             row++;
    109         }
    110     }
  • 相关阅读:
    excelhelp
    导入数据到GridView
    sql2005悠改sa
    状态存储管理 encode,decode,transfer
    Session持久化
    Microsoft SQL Server 2005 数据类型
    Cookie (HttpCookie的实例)
    role设计
    ajax
    poj 3370 Halloween treats 夜
  • 原文地址:https://www.cnblogs.com/chenpanpan/p/14431547.html
Copyright © 2020-2023  润新知