我在html中的基本表中显示数据库中的值。
<table>
<tr>
<td>
<strong><label>CONTAINER NUMBERS</label></strong> <br />
<asp:Label runat="server" ID="lblContainerNoMurphy"></asp:Label>
</td>
</tr>
<tr>
<td>
<strong><label>NO OF PIECES</label></strong> <br />
<asp:Label runat="server" ID="lblNoOfPiecesMurphy"></asp:Label>
</td>
</tr>
</table>
我在这里从数据库中获取值:
JobPiece piece = new JobPiece(Company.Current.CompanyID);
if (!string.IsNullOrEmpty(piece.ContainerNo))
{
lblContainerNoMurphy.Text = piece.ContainerNo;
}
if (!string.IsNullOrEmpty(piece.AdvisedQty))
{
lblNoOfPiecesMurphy.Text = piece.AdvisedQty;
}
问题是作业有多个容器编号和件数,但只显示一个。如何显示其他值?
答案 0 :(得分:0)
简单易用的控件将是 GridView 。从数据库中获取值并填充数据表并将该数据表用作gridview数据源。
GridView1.DataSource=YourDataSet.Tables[0];
GridView1.DataBind();
如果您想更改gridview的外观,可以使用CSS轻松完成。
答案 1 :(得分:0)
尝试像这样使用 Repeater
asp.net代码
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<strong><label>CONTAINER NUMBERS</label></strong><br />
<asp:Label runat="server" Text='<%#Eval("name of the field to show from db ex: ContainerNo") %>' ID="lblContainerNoMurphy"></asp:Label>
</td>
</tr>
<tr>
<td>
<strong><label>NO OF PIECES</label></strong><br />
<asp:Label runat="server" ID="lblNoOfPiecesMurphy" Text='<%#Eval("name of the field to show from db ex: AdvisedQty") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
C#代码
protected void Page_Load(object sender, EventArgs e)
{
List<JobPiece> items; // get your items from database and put it in this list
// fill repeater with your data
Repeater1.DataSource = items;
Repeater1.DataBind();
}