[英]Binding data to label with static text
<asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ID") %>' />
when I call the DataBind() function, ID is displayed as follows: 当我调用DataBind()函数时,ID显示如下:
14
but what if I want to display the ID like this: 但是,如果我想显示这样的ID,该怎么办:
ID: 14
this didn't work. 这没有用。
<asp:Label ID="IDLabel" runat="server" Text='ID: ' + '<%# Bind("ID") %>' />
Text='<%# "ID: " +Eval("ID").ToString() %>'
Try this one: 试试这个:
<asp:Label ID="IDLabel" runat="server" Text='<%# "ID: " +Eval("ID").ToString() %>' />
You cannot concatenate the values of attributes in XML. 您不能串联XML中的属性值。
You basically have XML like this: 您基本上具有这样的XML:
<element attribute="ID" + "sometext"/>
which is not valid - instead you need to let the preprocessor change the output of the XML so that only the value of the attribute is modified. 这是无效的-相反,您需要让预处理程序更改XML的输出,以便仅修改属性的值。
<asp:Label ID="IDLabel" runat="server" Text='<%# "ID: " + Bind("ID") %>' />
要么
<asp:Label ID="IDLabel" runat="server" Text='<%# String.Format("ID: {0}", Bind("ID")) %>' />
<asp:Label ID="IDLabel" runat="server" Text='<%# "ID: " +Eval("ID").ToString() %>' />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.