How to replace single quote from a string (BIND field) RRS feed

  • Question

  • User1478071981 posted


    I have a Gridview where I have to load some data read from an Oracle database.
    In one of the columns there is the field "surname" that may contain the ASCII character 39 (single quote).
    So how to replace the single quote?
    I've tried this:

                        <asp:Label ID="lblCognome" runat="server" Text='<%# Bind("SURNAME").Replace("'","''") %>'></asp:Label>

    but I get the error "tag server format not valid" (I translated the error message from italian so it may be different in english).
    Thanks, regards.


    Friday, August 4, 2017 1:28 PM

All replies

  • User347430248 posted

    Hi washburn_it,

    try something like mentioned below.

    <asp:Label ID="lblDemo" runat="server" 
         text='<%# (DirectCast(Eval("NAME"), String).Replace("\'", ""))%>' >



    Monday, August 7, 2017 5:32 AM
  • User1478071981 posted

    Hi Deepak,

    thanks for your suggestion, I tried with  Text='<%# Eval("COGNOME").ToString().Replace("\'", "") %>'> but, again, I get the "tag server format not valid" error.


    Monday, August 7, 2017 7:17 AM
  • User1478071981 posted

    I found the error.
    It was not on the code of the page itself but on the query passed to the datasource of the grid.
    I was able to correct it on the "codebehind" generated query and everything worked out.
    Anyway...thanks for the suggestion.


    Monday, August 7, 2017 10:45 AM
  • User347430248 posted

    Hi washburn_it,

    I can see that your issue is solved now.

    you had find the solution by yourself.

    this thread is still open.

    I suggest you to mark your own post as an answer.

    it will help other community members in future , who will meet with the same issue like yours.



    Tuesday, August 8, 2017 5:25 AM