Reputation: 13
Why does the second line work but not the first one? I get the "The server tag is not well formed". And the Guid I've copy into the second line is directly from the database.
< asp:Image runat="server" ImageUrl="~/Images/Avatar/Avatar.aspx?UserId=<%#DataBinder.Eval(Container.DataItem, "UserId")%>" />
< asp:Image runat="server" ImageUrl="~/Images/Avatar/Avatar.aspx?UserId=22AA736E-BD1B-4623-8E76-4769051F2E60" />
Upvotes: 1
Views: 1928
Reputation: 16245
An alternative method is to use String.Format(...)
.
<asp:TemplateField HeaderText="Avatar" SortExpression="LastName, FirstName">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# String.Format("~/Images/Avatar/Avatar.aspx?UserID={0}", Eval("UserID").ToString()) %>' />
</ItemTemplate>
</asp:TemplateField>
Upvotes: 1
Reputation: 1120
Try printing you <%#DataBinder.Eval(Container.DataItem, "UserId")%>
in a label. The way a Guid is formatted might not be exactly like what it looks like in the database. If i remeber correcctly, it might had {} around the Guid.
Upvotes: 0
Reputation: 4918
Or try
< asp:Image runat="server" ImageUrl='<%#"~/Images/Avatar/Avatar.aspx?UserId=" + DataBinder.Eval(Container.DataItem, "UserId")%>' />
Your problem was the double quotes. Your opening quote was a double quote so was being closed by the opening quote on "UserID". You should also always use single quotes when databinding anyway.
Upvotes: 0
Reputation: 94645
Put single quote around value of ImageUrl attribute.
<asp:Image runat="server"
ImageUrl='~/Images/Avatar/Avatar.aspx?
UserId=<%#DataBinder.Eval(Container.DataItem, "UserId")%>' />
Upvotes: 1