在 ASP.NET 中将 Eval 与 ImageURL 绑定
我正在尝试使用 Eval()
与 VB.NET 和 ASP.NET 绑定图像,但遇到了问题:
代码片段
<bri:ThumbViewer Id="Th1" runat="server"
ImageUrl='<%# Eval("Name", "~/SiteImages/ram/3/{0}") %>'
Height="100px"
Width="100px"
/>
我在代码中设置了 strImagePath
-后面的 as:
strImagePath ="~/SiteImages/ram/3/"
如何
~/SiteImages/ram/3/{0}
用变量 strImagePath
替换:?
I'm trying to bind an image using Eval()
with VB.NET and ASP.NET, but am running into issues:
Code snippet
<bri:ThumbViewer Id="Th1" runat="server"
ImageUrl='<%# Eval("Name", "~/SiteImages/ram/3/{0}") %>'
Height="100px"
Width="100px"
/>
I set strImagePath
in the code-behind as:
strImagePath ="~/SiteImages/ram/3/"
How can I replace:
~/SiteImages/ram/3/{0}
with the variable strImagePath
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这有点冗长,但你明白了。 您正在寻找的是 String.Format 方法。
您可以在 MSDN -> 上阅读更多相关信息。 String.Format
所以在你的情况下是:
只要在代码隐藏中将
strImagePath
设置为public
或protected
Thats a little bit verbose, but you get the idea. What you're looking for is the String.Format method.
You can read more about it over at MSDN -> String.Format
So in your case that would be:
as long as
strImagePath
is set topublic
orprotected
in your codebehind如果它是恒定的,你可以写(如果这是错误的,请原谅我):
如果不是:
Can you just write (and forgive me if this is wrong) if it is constant:
And if it isn't:
只需使用
图像路径即可来自数据表或cs
simply use
imagepath could be from datatable or cs
我个人更喜欢直接在代码隐藏中执行这些操作
,然后在代码隐藏中编写一些初始化或 DataBind() 方法,
因为特别是当您在团队中开发时,如果人们执行某些操作,则非常不方便且容易出错直接使用 Eval(...) 进行 ASPX 代码中的绑定,以及一些代码隐藏中的绑定。 我更喜欢使用代码隐藏,因为这样您只需查看代码就可以立即看到页面上发生的情况,而 ASPx 代码仅用于布局、控件定义(带有属性)等...
I personally prefer to do these things in the codebehind directly like
and then in the codebehind you have some initialize or DataBind() method where you write
This because especially when you develop in a team it is quite inconvenient and error-prone if people do some bindings in the ASPX code directly using Eval(...) and some in the codebehind. I prefer using the codebehind because then you immediately see what's going on on the page by just looking on your code, while your ASPx code is just for layout, definition of controls (with properties) etc...