我有几个 LinkButtons 的水平数据列表。按钮代表一个阶段,可以是“完成”(绿色图像)或“未开始”(灰色图像)。此外,每个这样的按钮必须包含一些文本和它的阶段编号,例如:“STAGE 1”、“STAGE 2”等...
我找到了几个解决方案,但没有一个能同时满足我的要求——图像和文本。
有没有人在这件事上有一个好的和优雅的解决方案?
这是html代码:
<asp:DataList ID="dlStatuses" runat="server" RepeatDirection="Horizontal"
onitemdatabound="dlStatuses_ItemDataBound"
onitemcommand="dlStatuses_ItemCommand">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0">
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="linkBtnStatuses" runat="server">
<asp:Image ID="linkButtonImage" runat="server" ImageAlign="Middle" BorderStyle="None"/>
</asp:LinkButton>
</ItemTemplate>
</asp:DataList>
以及背后的代码:
protected void dlStatuses_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRow row = (e.Item.DataItem as DataRowView).Row;
#region Place Icons
int StatusLevel = int.Parse(row["LevelID"].ToString());
LinkButton lnkButton = (e.Item.FindControl("linkBtnStatuses")) as LinkButton;
Image img = (e.Item.FindControl("linkButtonImage")) as Image;
//lnkButton.Text = " Stage No. " + StatusLevel.ToString();
switch (StatusLevel)
{
case 1:
img.ImageUrl = "~/style/images/Green.png";
break;
case 2:
img.ImageUrl = "~/style/images/Grey.png";
break;
}
}
提前致谢