过程:后台查询结果到DataTable,然后DataTable转为IList,然后逐行转为Dictionary。在一个方法中,用response.write()输出表格。然后在前端用<%%>调用该方法,使其输出页面代码
//前端页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GetQRInfo.aspx.cs" Inherits="QFMobileService.GetQRInfo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title></title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="bootstrap/css/bootstrap.css" rel="stylesheet" />
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet" />
<link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" />
<script src="bootstrap/js/bootstrap.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div><%InitData();%>
</div>
</form>
</body>
</html>
//后台代码
string rowguid;
protected void Page_Load(object sender, EventArgs e)
{
rowguid = Request["RowGuid"] != null ? Request["RowGuid"].ToString() : "";
}
public void InitData()
{
C_OrderEx coe = new C_OrderEx();
D_OrderEx doe = new D_OrderEx();
coe.GetModel(rowguid);
#region 初始化工序详情
DataTable dt_GX = doe.GetGongXu(coe.OrderChildId, coe.GuoCiId);
IList queryList2 = TransTableToEnumObj_GX(dt_GX);
if (queryList2 == null || queryList2.Count == 0)
return;
Response.Write("<div id=main;width=75%>");
Response.Write("<table class="table table-condensed table-bordered">");
Response.Write("<tr><td><b>工序</b></td>");
Response.Write("<td><b>机台<b></td>");
Response.Write("<td><b>执行人<b></td>");
Response.Write("<td><b>开始时间<b></td>");
Response.Write("<td><b>结束时间<b></td></tr>");
for (int i = 0; i < queryList2.Count; i++)
{
writetopage(queryList2[i]);
}
Response.Write("</table>");
Response.Write("</div>");
#endregion
}
private void writetopage<T>(T row)
{
Dictionary<string, object> dictProps = new Dictionary<string, object>();
Type t = row.GetType();
var proInfos = t.GetProperties().ToList();
proInfos.ForEach(p => { var objValue = p.GetValue(row, null).ToString(); dictProps.Add(p.Name, objValue); });
Response.Write("<tr><td>"+dictProps["WorkItemTempleteDtailName"]+"</td>");
Response.Write("<td>" + dictProps["ZhanTaiName"] + "</td>");
Response.Write("<td>" + dictProps["ZhiXingRenName"] + "</td>");
Response.Write("<td>" + dictProps["BeginTime"] + "</td>");
Response.Write("<td>" + dictProps["EndTime"] + "</td></tr>");
}
private IList TransTableToEnumObj_GX(DataTable dt0)
{
if (dt0 == null || dt0.Rows.Count < 1) return null;
var dtEnum = dt0.AsEnumerable();
var query = dtEnum.Select(p => new
{
WorkItemTempleteDtailName = p["WorkItemTempleteDtailName"],
ZhanTaiName = p["ZhanTaiName"],
ZhiXingRenName = p["ZhiXingRenName"],
BeginTime = p["BeginTime"],
EndTime = p["EndTime"]
}).ToList();
return query;
}