asp:Table控件对于设置表格还是很方便的
页面布局:
<asp:Table ID="Table1" runat="server" BorderWidth="1" GridLines="Both" Width="800px">
<asp:TableRow>
<asp:TableCell HorizontalAlign="Right" Width="200px">设备名称: </asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="200px">xxxxx</asp:TableCell>
<asp:TableCell HorizontalAlign="Right" Width="200px">所属站场: </asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="200px">yyyy</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Right" Width="200px">设备型号: </asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="200px">xxxxx</asp:TableCell>
<asp:TableCell HorizontalAlign="Right" Width="200px">电压(kV): </asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="200px">yyyy</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Right" Width="200px">额定容量(kVA): </asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="200px">xxxxx</asp:TableCell>
<asp:TableCell HorizontalAlign="Right" Width="200px">联结组标: </asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="200px">yyyy</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Right" Width="200px">空载损耗(W): </asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="200px">xxxxx</asp:TableCell>
<asp:TableCell HorizontalAlign="Right" Width="200px">负载损耗(W): </asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="200px">yyyy</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Right" Width="200px">空载电流(%): </asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="200px">xxxxx</asp:TableCell>
<asp:TableCell HorizontalAlign="Right" Width="200px">短路阻抗(%): </asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="200px">yyyy</asp:TableCell>
</asp:TableRow>
</asp:Table>
后台代码:
Table2.Rows[2].Cells[1].Text = dt.Rows[0]["WenshengShuiping"].ToString();
if (b[4] >= 24)
Table2.Rows[2].Cells[1].ForeColor = System.Drawing.Color.Red;
Table2.Rows[2].Cells[3].Text = dt.Rows[0]["ZaoshengShuiping"].ToString();
Table2.Rows[3].Cells[1].Text = dt.Rows[0]["JueyuanDianzu"].ToString();
if (b[5] >= 20)
Table2.Rows[3].Cells[1].ForeColor = System.Drawing.Color.Red;
Table2.Rows[3].Cells[3].Text = dt.Rows[0]["Xishoubi"].ToString();
if (b[6] >= 20)
Table2.Rows[3].Cells[3].ForeColor = System.Drawing.Color.Red;
效果:
行合并操作:
在页面设置一个单元格:
<asp:TableRow>
<asp:TableCell HorizontalAlign="Left" Width="200px">油中溶解气体特征量</asp:TableCell>
</asp:TableRow>
在代码中设置其列跨越数目,实现横向单元合并
Table2.Rows[0].Cells[0].ColumnSpan = 4;
纵向合并与此类似
Table2.Rows[0].Cells[0].RowSpan = 4;