由于 Eval/DataItem 会给 object/String 返回值。为了转换成 3,546 字节输出,需要将其转换成整数。对于该onitemdatabound
事件,将需要注册。
标记
<asp:ListView ID="ListView1" runat="server" onitemdatabound="rpt_ItemDataBound">
<LayoutTemplate>
<table class="myclass">
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><asp:Label ID="lbl" runat="server" ></asp:Label></td>
</tr>
</ItemTemplate>
</asp:ListView>
代码背后
protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item)
{
Label lbl= (Label)e.Item.FindControl("lbl");
lbl.Text = String.Format("{0:#,### bytes}",
Convert.ToInt32(((YourClassName)e.Item.DataItem).YourProperty);
}
}