The syntax highlighter in the question's code shows the problem perfectly: if you use double quotes inside an XML attribute (and that is excactly what the Value= inside the asp.HiddenField is) after starting the attribute value with a double quote, this effectively ends the string literal.
XML allows you to use either single quotes (') or double quotes (") to delimit an attribute's value, but the quotes have to match. XML always takes the first matching quote to end the corresponding starting quote.
So if you want to use double quotes inside the attribute value (because C# needs them), you have to use single quotes to delimit it.
This code works:
<asp:HiddenField runat="server" Value='<% #Eval("ColumnName") %>' />
for the content of the <% … %> part is interpreted in .net, the quotes inside the attribute value have to be double quotes. For a programming language that accepts strings delimited with single quotes, the following would work, too:
<asp:HiddenField runat="server" Value="<% #Eval('ColumnName') %>" />
Replied on Jan 24 2011 6:21AM
.