Reputation: 3293
<asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ID") %>' />
when I call the DataBind() function, ID is displayed as follows:
14
but what if I want to display the ID like this:
ID: 14
this didn't work.
<asp:Label ID="IDLabel" runat="server" Text='ID: ' + '<%# Bind("ID") %>' />
Upvotes: 0
Views: 2215
Reputation: 8005
Try this one:
<asp:Label ID="IDLabel" runat="server" Text='<%# "ID: " +Eval("ID").ToString() %>' />
You cannot concatenate the values of attributes in XML.
You basically have XML like this:
<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.
Upvotes: 1
Reputation: 12874
<asp:Label ID="IDLabel" runat="server" Text='<%# "ID: " +Eval("ID").ToString() %>' />
Upvotes: 0
Reputation: 26386
<asp:Label ID="IDLabel" runat="server" Text='<%# "ID: " + Bind("ID") %>' />
Or
<asp:Label ID="IDLabel" runat="server" Text='<%# String.Format("ID: {0}", Bind("ID")) %>' />
Upvotes: 0