本文主要是介绍table伪动态数据绑定,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
要实现如下图的效果
前台FormView控件的项模板用table来简单布局下:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID" Width="100%">
<ItemTemplate>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" style="background-color: #D7E8F8">
<asp:Image ImageUrl="~/AQJDGL/Security/jzyx.jpg" runat="server" ID="Image1" />
</td>
<td align="center" style="width: 20%" id="tbsj1" runat="server">
//这里加 的作用是即使从数据库中取出的不够四个,table的cell之间还是可以看见是有线分割着的
</td>
<td align="center" style="width: 20%" id="tbsj2" runat="server">
</td>
<td align="center" style="width: 20%" id="tbsj3" runat="server">
</td>
<td align="center" style="width: 20%" id="tbsj4" runat="server">
</td>
</tr>
<tr>
<td align="center" style="font-weight: bold; height: 30px; width: 5%">
<asp:Label ID="Label27" runat="server" Text="主机组"></asp:Label>
</td>
<td align="center" style="font-weight: bold; height: 30px; width: 15%">
<asp:Label ID="Label1" runat="server" Text="油位、气味、声音、震动、温度"></asp:Label>
</td>
<td align="center" style="width: 20%" id="tbzjz1" runat="server">
</td>
<td align="center" style="width: 20%" id="tbzjz2" runat="server">
</td>
<td align="center" style="width: 20%" id="tbzjz3" runat="server">
</td>
<td align="center" style="width: 20%" id="tbzjz4" runat="server">
</td>
</tr>
<tr>
<td align="center" style="font-weight: bold; height: 30px; width: 5%">
<asp:Label ID="Label2" runat="server" Text="供水系统"></asp:Label>
</td>
<td align="center" style="font-weight: bold; height: 30px; width: 15%">
<asp:Label ID="Label3" runat="server" Text="压力、声音、滴漏、震动"></asp:Label>
</td>
<td align="center" style="width: 20%" id="tbgsxt1" runat="server">
</td>
<td align="center" style="width: 20%" id="tbgsxt2" runat="server">
</td>
<td align="center" style="width: 20%" id="tbgsxt3" runat="server">
</td>
<td align="center" style="width: 20%" id="tbgsxt4" runat="server">
</td>
</tr>
<tr>
<td align="center" style="font-weight: bold; height: 30px; width: 5%">
<asp:Label ID="Label4" runat="server" Text="供气系统"></asp:Label>
</td>
<td align="center" style="font-weight: bold; height: 30px; width: 15%">
<asp:Label ID="Label5" runat="server" Text="压力、声音、泄漏"></asp:Label>
</td>
<td align="center" style="width: 20%" id="tbgqxt1" runat="server">
</td>
<td align="center" style="width: 20%" id="tbgqxt2" runat="server">
</td>
<td align="center" style="width: 20%" id="tbgqxt3" runat="server">
</td>
<td align="center" style="width: 20%" id="tbgqxt4" runat="server">
</td>
</tr>
<tr>
<td align="center" style="font-weight: bold; height: 30px; width: 5%">
<asp:Label ID="Label6" runat="server" Text="高低压柜"></asp:Label>
</td>
<td align="center" style="font-weight: bold; height: 30px; width: 15%">
<asp:Label ID="Label7" runat="server" Text=""></asp:Label>
</td>
<td align="center" style="width: 20%" id="tbgdyg1" runat="server">
</td>
<td align="center" style="width: 20%" id="tbgdyg2" runat="server">
</td>
<td align="center" style="width: 20%" id="tbgdyg3" runat="server">
</td>
<td align="center" style="width: 20%" id="tbgdyg4" runat="server">
</td>
</tr>
<tr>
<td align="center" style="font-weight: bold; height: 30px; width: 5%">
<asp:Label ID="Label8" runat="server" Text="上游液压门"></asp:Label>
</td>
<td align="center" style="font-weight: bold; height: 30px; width: 15%">
<asp:Label ID="Label9" runat="server" Text=""></asp:Label>
</td>
<td align="center" style="width: 20%" id="tbsyyym1" runat="server">
</td>
<td align="center" style="width: 20%" id="tbsyyym2" runat="server">
</td>
<td align="center" style="width: 20%" id="tbsyyym3" runat="server">
</td>
<td align="center" style="width: 20%" id="tbsyyym4" runat="server">
</td>
</tr>
<tr>
<td align="center" style="font-weight: bold; height: 30px; width: 5%">
<asp:Label ID="Label10" runat="server" Text="下游检修门"></asp:Label>
</td>
<td align="center" style="font-weight: bold; height: 30px; width: 15%">
<asp:Label ID="Label12" runat="server" Text="吊 挂"></asp:Label>
</td>
<td align="center" style="width: 20%" id="tbxyjxm1" runat="server">
</td>
<td align="center" style="width: 20%" id="tbxyjxm2" runat="server">
</td>
<td align="center" style="width: 20%" id="tbxyjxm3" runat="server">
</td>
<td align="center" style="width: 20%" id="tbxyjxm4" runat="server">
</td>
</tr>
<tr>
<td align="center" style="font-weight: bold; height: 30px; width: 5%">
<asp:Label ID="Label13" runat="server" Text="拍 门"></asp:Label>
</td>
<td align="center" style="font-weight: bold; height: 30px; width: 15%">
<asp:Label ID="Label14" runat="server" Text="绞座、拐臂、销"></asp:Label>
</td>
<td align="center" style="width: 20%" id="tbpm1" runat="server">
</td>
<td align="center" style="width: 20%" id="tbpm2" runat="server">
</td>
<td align="center" style="width: 20%" id="tbpm3" runat="server">
</td>
<td align="center" style="width: 20%" id="tbpm4" runat="server">
</td>
</tr>
<tr>
<td align="center" style="font-weight: bold; height: 30px; width: 5%">
<asp:Label ID="Label15" runat="server" Text="10KV 站变"></asp:Label>
</td>
<td align="center" style="font-weight: bold; height: 30px; width: 15%">
<asp:Label ID="Label16" runat="server" Text="声音、温度"></asp:Label>
</td>
<td align="center" style="width: 20%" id="tbzb1" runat="server">
</td>
<td align="center" style="width: 20%" id="tbzb2" runat="server">
</td>
<td align="center" style="width: 20%" id="tbzb3" runat="server">
</td>
<td align="center" style="width: 20%" id="tbzb4" runat="server">
</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
后台cs文件中给这些td赋值:
首先需要添加引用:
using System.Web.UI.HtmlControls;
DM dm = new DM();
string strSQL = "SELECT top 4 * FROM [机组运行巡视检查记录附表] WHERE 主表ID=" + int.Parse(id.ToString()) + " order by ID";
DataSet ds = dm.getsql(strSQL);
//获取数据集中数据个数
int summ = ds.Tables[0].Rows.Count;
for (int i = 1; i < summ + 1; i++)
{
//通过循环遍历给td单元格赋值
((HtmlTableCell)FormView1.FindControl("tbsj" + i.ToString())).InnerText = ds.Tables[0].Rows[i - 1]["检查时段"].ToString();
((HtmlTableCell)FormView1.FindControl("tbzjz" + i.ToString())).InnerText = ds.Tables[0].Rows[i-1]["主机组情况"].ToString();
((HtmlTableCell)FormView1.FindControl("tbgsxt" + i.ToString())).InnerText = ds.Tables[0].Rows[i-1]["供水系统情况"].ToString();
((HtmlTableCell)FormView1.FindControl("tbgqxt" + i.ToString())).InnerText = ds.Tables[0].Rows[i-1]["供气系统情况"].ToString();
((HtmlTableCell)FormView1.FindControl("tbgdyg" + i.ToString())).InnerText = ds.Tables[0].Rows[i-1]["高低压柜情况"].ToString();
((HtmlTableCell)FormView1.FindControl("tbsyyym" + i.ToString())).InnerText = ds.Tables[0].Rows[i-1]["上游液压门情况"].ToString();
((HtmlTableCell)FormView1.FindControl("tbxyjxm" + i.ToString())).InnerText = ds.Tables[0].Rows[i - 1]["下游检修门情况"].ToString();
((HtmlTableCell)FormView1.FindControl("tbpm" + i.ToString())).InnerText = ds.Tables[0].Rows[i - 1]["拍门情况"].ToString();
((HtmlTableCell)FormView1.FindControl("tbzb" + i.ToString())).InnerText = ds.Tables[0].Rows[i - 1]["站变情况"].ToString();
}
这篇关于table伪动态数据绑定的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!