<asp:Repeater ID="rptStatus" runat="server" OnItemDataBound="rptStatus_ItemDataBound">
<HeaderTemplate>
<table>
<tr>
</HeaderTemplate>
<ItemTemplate>
<td>
<asp:Image ID="imgStatus" runat="server" ToolTip='<%#Eval("车辆状态") %>' />
</td>
<td>
<asp:Label ID="lblCPH" runat="server" Text='<%#Eval("车牌号") %>'></asp:Label>
</td>
</ItemTemplate>
<FooterTemplate>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
private int i=0;
protected void rptStatus_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//这里根据图片的ToolTip属性值,重新设置ImageUrl属性值,指示车辆的使用状态
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Image image = (Image)e.Item.FindControl("imgStatus");
int toolTip = int.Parse(image.ToolTip.ToString());
if (toolTip == 0)
{
image.ImageUrl = "~/images/ky.jpg";
}
else if (toolTip == 1)
{
image.ImageUrl = "~/images/cc.jpg";
}
else if (toolTip == 2)
{
image.ImageUrl = "~/images/wx.jpg";
}
else if (toolTip == 3)
{
image.ImageUrl = "~/images/qt.jpg";
}
}
if (i % 7 == 0 && i > 0)
{
e.Item.Controls.Add(new LiteralControl("</tr><tr>"));
}
i++;
}
//repeater控件绑定
private void BindRepeater()
{
DBHandler dbh = DBHandlerFactory.GetHandler("VehicleConnectionString");
dbh.CommandText = "select 车牌号,车辆状态 from 车辆档案表";
DataTable dt = dbh.ExecuteDataTable();
this.rptStatus.DataSource = dt;
this.rptStatus.DataBind();
}
显示效果如下图: