in

Corey Roth and Friends Blogs

Group site for developer blogs dealing with (usually) Ionic, .NET, SharePoint, Office 365, Mobile Development, and other Microsoft products, as well as some discussion of general programming related concepts.

Cory Robinson's Blog

February 2008 - Posts

  • HtmlEncodeFormatString errors in GridView BoundField after precompile

    I ran across an issue today where my data format string was not being applied to my data in a gridview.  It worked locally, but not in dev or test.  Here's what I had:

    <asp:BoundField DataField="GrandTotal" HeaderText="Grand Total" ReadOnly="True" SortExpression="GrandTotal" DataFormatString="{0:c}" />

     

    Ok what would make this render differently in dev?  I looked at the HtmlEncodeFormatString property of the BoundField, noticing that setting it to false made the formatting go away locally as well.  So I assumed that I needed to add HtmlEncodeFormatString="true" in dev to make it work.  However, I got the following error message:

     

    Error: Type 'System.Web.UI.WebControls.BoundField' does not have a public property named 'HtmlEncodeFormatString'.

     

    No idea why this is happening.  I googled the error but found nothing useful.  There is an issue with ASP.NET 3.5 and this property defaulting to true, but I don't have 3.5 installed on the dev box.  So that can't be it.

     

    So I had the bright idea to convert this BoundField to a template column (by clicking the linkbutton in the Edit Columns designer).  I got this:

     

    <asp:TemplateField HeaderText="Grand Total" SortExpression="GrandTotal">

      <ItemTemplate>

        <asp:Label ID="Label1" runat="server" Text='<%# Bind("GrandTotal", "{0:c}") %>'></asp:Label>

      </ItemTemplate>

    </asp:TemplateField>

     

    Magically, this works both locally and in dev.  I have no idea why.

2019.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems