Prev: Control contents disappear after postback
Next: Checking/unchecking all checkboxes in the one column of the gridview
From: Jonathan Wood on 17 May 2010 21:57 I'm using a GridView control with a TemplateField column. It works fine except I see the text is not HTML-encoded. Here's the column template: <asp:TemplateField HeaderText="Title" SortExpression="ActTitle"> <ItemTemplate> <asp:HyperLink ID="lnkActivity" runat="server" > <asp:Label ID="Label1" runat="server" Text='<%# Bind("ActTitle") %>'></asp:Label> </asp:HyperLink> </ItemTemplate> </asp:TemplateField> When editing GridView columns, there is an option to specify whether or not the data is encoded. But this is not the case with templated columns. I've always known the Label control to HTML but, according to http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.label.text.aspx: "The Text property can include HTML. If it does, the HTML will be passed unchanged to the browser, where is might be interpreted as markup and not as text." I thought if I could move the Bind() to the inner text of the label control that might resolve this but I get an error saying Bind can only be assigned in a control property. My datasource is a DataSet so the only way I could manually encode it is by iterating through the entire dataset. Does anyone know how I can get this data HTML-encoded? Thanks. Jonathan |