動態生成Table內文字換行。

後臺動態生成table,並把td內的文字進行換行。ui

前臺:this

<body style="width:100%;height:540px;margin-left:0px;margin-top:0px;overflow:scroll">
<form id="form1" style="font-size:10pt" runat="server">
<div >
    <table width="95%"  border="0"  align="center" cellpadding="3" style="table-layout:fixed;" cellspacing="1" bgcolor="#A2C1C8" id="tbContent" runat="server">
        <tr>
            <td colspan="3" style="background-color:#deebef" align="center" >流程開始</td>
        </tr>
    </table>
    
</div>
</form>
</body>

後臺:spa

  protected void show()
    {
        try
        {
            string eventinfoid = Server.UrlDecode(Request.QueryString["eventinfoid"].ToString());
            DataTable dtFlowOperationState = new DataTable();
            dtFlowOperationState = flowBLL.GetList(" eventid='" + eventinfoid + "' order by newaddtime asc").Tables[0];
            int i = 1;
            foreach (DataRow dr in dtFlowOperationState.Rows)
            {
                HtmlTableRow row = new HtmlTableRow();
                HtmlTableCell cell = new HtmlTableCell();
                cell.Align = "center";
                cell.BgColor = "#f7f7f7";
                cell.InnerText = "" + i.ToString() + "";
               
                i++;
                row.Cells.Add(cell);

                cell = new HtmlTableCell();
                cell.Align = "left";
                cell.BgColor = "#f7f7f7";
               
                string strTemp = "";
                string UserName = getUserNameByID(dr["dealpeopleid"].ToString());
                string dealtypeO = dr["dealtype"].ToString();
                string delatime = dr["dealtime"].ToString();
                string newaddtime = dr["newaddtime"].ToString();
                if (!string.IsNullOrEmpty(delatime) && !string.IsNullOrEmpty(newaddtime))
                {
                    strTemp += UserName + "[<font color='#008200'>" + dealtypeO + "&nbsp;用時:" + getTimeCount(Convert.ToDateTime(delatime), Convert.ToDateTime(newaddtime)) + "</font>]<br />";
                    strTemp += "開始於:" + newaddtime + "<br />";
                    strTemp += "步驟結束於:" + delatime + "<br />";
                }
                else
                {
                    strTemp += UserName + "[<font color='#008200'>" + dealtypeO + "&nbsp;用時:0天0時0分0秒" +"</font>]<br />";
                    strTemp += "開始於:" + newaddtime + "<br />";
                    strTemp += "步驟結束於:正在處理中....<br />";
                }
                cell.InnerHtml = strTemp;
                row.Cells.Add(cell);

                cell = new HtmlTableCell();
                cell.Align = "left";
                cell.VAlign = "top";
                cell.BgColor = "#f7f7f7";
                cell.Style.Add("word-wrap","break-word");//控制table換行
                cell.Width = "400";
                cell.InnerText = "意見:" + dr["dealcontext"].ToString();
                row.Cells.Add(cell);
                this.tbContent.Rows.Add(row);
            }
        }
        catch (System.Exception ex)
        {
            //ProcessException("JHLOA_New", "WorkFlow_Flow_PreviewFlowView", "show", ex.Message);
            //Response.Redirect("../../error.aspx?id=3");
        }
    }
    #region 獲取時間差
    public string getTimeCount(DateTime onTime, DateTime offTime)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            TimeSpan ts = onTime - offTime;
            if (ts.Days > 0)
            {
                sb.Append(ts.Days.ToString());
                sb.Append("");
            }
            sb.Append(ts.Hours.ToString());
            sb.Append("小時");
            sb.Append(ts.Minutes.ToString());
            sb.Append("");
            sb.Append(ts.Seconds.ToString());
            sb.Append("");
        }
        catch (System.Exception ex)
        {

        }
        return sb.ToString();
    }
    #endregion

其中:code

cell.Style.Add("word-wrap","break-word");//控制table換行
cell.Width = "400";orm

控制意見進行換行。server

相關文章
相關標籤/搜索