C# 对 Bind 的调用必须分配给模板内控件的属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/779001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
A call to Bind must be assigned to a property of a control inside a template
提问by Kolten
I want to show a thumbnail image inside a gridview instead of the text. This is what I am trying:
我想在 gridview 中显示缩略图而不是文本。这就是我正在尝试的:
<asp:TemplateField HeaderText="Image" SortExpression="Image">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Image") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Image ID="thumbnail" runat="server" ImageUrl="<%# Bind("Image") %>" />
</ItemTemplate>
</asp:TemplateField>
What is the syntax i should be using?
我应该使用什么语法?
采纳答案by Steve Willcock
Try using Evalinstead of Bindfor the ImageUrl - this is one way binding.
If you are still having problems, using single quotes instead of double quotes around the property might help:
<asp:Image ID="thumbnail" runat="server" ImageUrl='<%# Eval("Image") %>' />
尝试对 ImageUrl使用Eval而不是Bind- 这是一种绑定方式。
如果您仍然遇到问题,在属性周围使用单引号而不是双引号可能会有所帮助:
<asp:Image ID="thumbnail" runat="server" ImageUrl='<%# Eval("Image") %>' />