2011-11-03 66 views
0

我想在asp.net(使用vb.net)中为我的图像分配一个特定的宽度。 所以我用下面的代码:如何在ASP.NET中将浮点数转换为整数?

<asp:Image ID="PercentageImage" runat="server" Height="7px" 
      Width='<%# Eval("votsGraph") %>' 
      ImageUrl="~/images/bar.JPG" /> 

那么我该如何施展这一个? (该类型的votsGraph是浮动。)

+0

请注意,这个问题真的*只*关于VB.NET而不是ASP.NET。 – 2011-11-03 15:31:35

+0

@pst在我的回答中,我还必须更正一些ASP.NET标记以获得OP的要求。 – Curt

+0

@Curt是的,这就是为什么它被提出并接受;-)试图显示[现代] ASP.NET只是基础语言/运行时的顶层。 – 2011-11-03 15:46:58

回答

2

使用CInt()

<asp:Image ID="PercentageImage" runat="server" Height="7px" Width='<%# string.format("{0}px", cint(Eval("votsGraph"))) %>' ImageUrl="~/images/bar.JPG" /> 

我还添加了String.Format()到你的代码,你失踪px

Width='<%# string.format("{0}px", cint(Eval("votsGraph"))) %>' 
+0

是的,这是答案,非常感谢。 – HAJJAJ