Griview cells Text Special Characters

Discussion in 'ASP .Net Web Controls' started by john, Oct 12, 2007.

  1. john

    john Guest

    When I get a Gridview Cell contents that has a Special Character in its data
    such as an & or " it returns it constant & or " instead of the
    actual Character.



    Any way to modify this code to get the actual Character as it is displayed
    in the cell?



    Sample cell actual text: A & C Hauling



    dim ven as String

    ven = me.Gridview1.SelectedRow.Cells(2).Text



    Result to ven variable is A & Hauling



    Thanks

    John
     
    john, Oct 12, 2007
    #1
    1. Advertising

  2. john

    Phil H Guest

    John

    I take it that the code is in response to the "selected-index_changed"
    event (Y/N?)

    If so then you need to retrieve the data from the original data source
    rather than the content of grid cells. The easiest way is to obtain
    the record's primary key value and query the source programatically.

    On 12 Oct, 10:38, "john" <> wrote:
    > When I get a Gridview Cell contents that has a Special Character in its data
    > such as an & or " it returns it constant &amp; or &quot; instead of the
    > actual Character.
    >
    > Any way to modify this code to get the actual Character as it is displayed
    > in the cell?
    >
    > Sample cell actual text: A & C Hauling
    >
    > dim ven as String
    >
    > ven = me.Gridview1.SelectedRow.Cells(2).Text
    >
    > Result to ven variable is A &amp; Hauling
    >
    > Thanks
    >
    > John
     
    Phil H, Oct 12, 2007
    #2
    1. Advertising

  3. john

    john Guest

    Actually I am pulling the cell contents into a formview from the already
    selected record, but I think considering the few special Characters I would
    to just do replace on the cell data than have to pull from the datasource
    all over again.

    I was hoping there was a simple way to convert or cast it from its constant.

    Thanks for your reply.

    "Phil H" <> wrote in message
    news:...
    > John
    >
    > I take it that the code is in response to the "selected-index_changed"
    > event (Y/N?)
    >
    > If so then you need to retrieve the data from the original data source
    > rather than the content of grid cells. The easiest way is to obtain
    > the record's primary key value and query the source programatically.
    >
    > On 12 Oct, 10:38, "john" <> wrote:
    >> When I get a Gridview Cell contents that has a Special Character in its
    >> data
    >> such as an & or " it returns it constant &amp; or &quot; instead of the
    >> actual Character.
    >>
    >> Any way to modify this code to get the actual Character as it is
    >> displayed
    >> in the cell?
    >>
    >> Sample cell actual text: A & C Hauling
    >>
    >> dim ven as String
    >>
    >> ven = me.Gridview1.SelectedRow.Cells(2).Text
    >>
    >> Result to ven variable is A &amp; Hauling
    >>
    >> Thanks
    >>
    >> John

    >
    >
     
    john, Oct 13, 2007
    #3
  4. Hi John,

    For the character formatting, are you using the default "BoundField"? If
    so, gridview's boundfield will perform html encoding on boundfield
    content(when set via databinding) so as to avoid some potential malicious
    injected script code:

    #BoundField.HtmlEncode Property
    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfiel
    d.htmlencode.aspx

    You can try turn it off if you're sure the characters in the content is
    safe and non characters in it will bread page's html source(e.g it doesn't
    contain chars like '<', '>'....).

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.





    --------------------
    >From: "john" <>
    >References: <u#>

    <>
    >Subject: Re: Griview cells Text Special Characters
    >Date: Sat, 13 Oct 2007 18:27:01 -0400
    >
    >Actually I am pulling the cell contents into a formview from the already
    >selected record, but I think considering the few special Characters I

    would
    >to just do replace on the cell data than have to pull from the datasource
    >all over again.
    >
    >I was hoping there was a simple way to convert or cast it from its

    constant.
    >
    >Thanks for your reply.
    >
    >"Phil H" <> wrote in message
    >news:...
    >> John
    >>
    >> I take it that the code is in response to the "selected-index_changed"
    >> event (Y/N?)
    >>
    >> If so then you need to retrieve the data from the original data source
    >> rather than the content of grid cells. The easiest way is to obtain
    >> the record's primary key value and query the source programatically.
    >>
    >> On 12 Oct, 10:38, "john" <> wrote:
    >>> When I get a Gridview Cell contents that has a Special Character in its
    >>> data
    >>> such as an & or " it returns it constant &amp; or &quot; instead of the
    >>> actual Character.
    >>>
    >>> Any way to modify this code to get the actual Character as it is
    >>> displayed
    >>> in the cell?
    >>>
    >>> Sample cell actual text: A & C Hauling
    >>>
    >>> dim ven as String
    >>>
    >>> ven = me.Gridview1.SelectedRow.Cells(2).Text
    >>>
    >>> Result to ven variable is A &amp; Hauling
    >>>
    >>> Thanks
    >>>
    >>> John

    >>
    >>

    >
    >
    >
     
    Steven Cheng[MSFT], Oct 15, 2007
    #4
  5. john

    marss Guest

    On 12 , 12:38, "john" <> wrote:

    > Any way to modify this code to get the actual Character as it is displayed
    > in the cell?
    >
    > Sample cell actual text: A & C Hauling
    >
    > dim ven as String
    >
    > ven = me.Gridview1.SelectedRow.Cells(2).Text
    >
    > Result to ven variable is A &amp; Hauling


    Try this:

    ven = Server.HtmlDecode(me.Gridview1.SelectedRow.Cells(2).Text)

    Regards,
    Mykola
    http://marss.co.ua
     
    marss, Oct 16, 2007
    #5
  6. john

    john Guest

    Thanks for all your input, I tried setting HtmlEncode to False and that
    worked. Seeing as I do not allow any editing of that cell, I take it that it
    will be safe to do.

    But I also want to try the latest Idea of: Server.HtmlDecode to see how that
    works also for the times when I need that security.

    Thanks for all your help.

    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hi John,
    >
    > For the character formatting, are you using the default "BoundField"? If
    > so, gridview's boundfield will perform html encoding on boundfield
    > content(when set via databinding) so as to avoid some potential malicious
    > injected script code:
    >
    > #BoundField.HtmlEncode Property
    > http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfiel
    > d.htmlencode.aspx
    >
    > You can try turn it off if you're sure the characters in the content is
    > safe and non characters in it will bread page's html source(e.g it doesn't
    > contain chars like '<', '>'....).
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    >
    > ==================================================
    >
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications.
    >
    >
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >
    > ==================================================
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
    >
    >
    >
    >
    > --------------------
    >>From: "john" <>
    >>References: <u#>

    > <>
    >>Subject: Re: Griview cells Text Special Characters
    >>Date: Sat, 13 Oct 2007 18:27:01 -0400
    >>
    >>Actually I am pulling the cell contents into a formview from the already
    >>selected record, but I think considering the few special Characters I

    > would
    >>to just do replace on the cell data than have to pull from the datasource
    >>all over again.
    >>
    >>I was hoping there was a simple way to convert or cast it from its

    > constant.
    >>
    >>Thanks for your reply.
    >>
    >>"Phil H" <> wrote in message
    >>news:...
    >>> John
    >>>
    >>> I take it that the code is in response to the "selected-index_changed"
    >>> event (Y/N?)
    >>>
    >>> If so then you need to retrieve the data from the original data source
    >>> rather than the content of grid cells. The easiest way is to obtain
    >>> the record's primary key value and query the source programatically.
    >>>
    >>> On 12 Oct, 10:38, "john" <> wrote:
    >>>> When I get a Gridview Cell contents that has a Special Character in its
    >>>> data
    >>>> such as an & or " it returns it constant &amp; or &quot; instead of the
    >>>> actual Character.
    >>>>
    >>>> Any way to modify this code to get the actual Character as it is
    >>>> displayed
    >>>> in the cell?
    >>>>
    >>>> Sample cell actual text: A & C Hauling
    >>>>
    >>>> dim ven as String
    >>>>
    >>>> ven = me.Gridview1.SelectedRow.Cells(2).Text
    >>>>
    >>>> Result to ven variable is A &amp; Hauling
    >>>>
    >>>> Thanks
    >>>>
    >>>> John
    >>>
    >>>

    >>
    >>
    >>

    >
     
    john, Oct 16, 2007
    #6
  7. You're welcome:)

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------
    >From: "john" <>
    >References: <u#>

    <>
    <>
    <>
    >Subject: Re: Griview cells Text Special Characters
    >Date: Tue, 16 Oct 2007 18:20:37 -0400


    >Thanks for all your input, I tried setting HtmlEncode to False and that
    >worked. Seeing as I do not allow any editing of that cell, I take it that

    it
    >will be safe to do.
    >
    >But I also want to try the latest Idea of: Server.HtmlDecode to see how

    that
    >works also for the times when I need that security.
    >
    >Thanks for all your help.
    >
    >"Steven Cheng[MSFT]" <> wrote in message
    >news:...
    >> Hi John,
    >>
    >> For the character formatting, are you using the default "BoundField"? If
    >> so, gridview's boundfield will perform html encoding on boundfield
    >> content(when set via databinding) so as to avoid some potential malicious
    >> injected script code:
    >>
    >> #BoundField.HtmlEncode Property
    >>

    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfiel
    >> d.htmlencode.aspx
    >>
    >> You can try turn it off if you're sure the characters in the content is
    >> safe and non characters in it will bread page's html source(e.g it

    doesn't
    >> contain chars like '<', '>'....).
    >>
    >> Sincerely,
    >>
    >> Steven Cheng
    >>
    >> Microsoft MSDN Online Support Lead
    >>
    >>
    >>
    >> ==================================================
    >>
    >> Get notification to my posts through email? Please refer to
    >>

    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    >> ications.
    >>
    >>
    >>
    >> Note: The MSDN Managed Newsgroup support offering is for non-urgent

    issues
    >> where an initial response from the community or a Microsoft Support
    >> Engineer within 1 business day is acceptable. Please note that each

    follow
    >> up response may take approximately 2 business days as the support
    >> professional working with you may need further investigation to reach the
    >> most efficient resolution. The offering is not appropriate for situations
    >> that require urgent, real-time or phone-based interactions or complex
    >> project analysis and dump analysis issues. Issues of this nature are best
    >> handled working with a dedicated Microsoft Support Engineer by contacting
    >> Microsoft Customer Support Services (CSS) at
    >> http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >>
    >> ==================================================
    >>
    >>
    >> This posting is provided "AS IS" with no warranties, and confers no
    >> rights.
    >>
    >>
    >>
    >>
    >>
    >> --------------------
    >>>From: "john" <>
    >>>References: <u#>

    >> <>
    >>>Subject: Re: Griview cells Text Special Characters
    >>>Date: Sat, 13 Oct 2007 18:27:01 -0400
    >>>
    >>>Actually I am pulling the cell contents into a formview from the already
    >>>selected record, but I think considering the few special Characters I

    >> would
    >>>to just do replace on the cell data than have to pull from the datasource
    >>>all over again.
    >>>
    >>>I was hoping there was a simple way to convert or cast it from its

    >> constant.
    >>>
    >>>Thanks for your reply.
    >>>
    >>>"Phil H" <> wrote in message
    >>>news:...
    >>>> John
    >>>>
    >>>> I take it that the code is in response to the "selected-index_changed"
    >>>> event (Y/N?)
    >>>>
    >>>> If so then you need to retrieve the data from the original data source
    >>>> rather than the content of grid cells. The easiest way is to obtain
    >>>> the record's primary key value and query the source programatically.
    >>>>
    >>>> On 12 Oct, 10:38, "john" <> wrote:
    >>>>> When I get a Gridview Cell contents that has a Special Character in

    its
    >>>>> data
    >>>>> such as an & or " it returns it constant &amp; or &quot; instead of

    the
    >>>>> actual Character.
    >>>>>
    >>>>> Any way to modify this code to get the actual Character as it is
    >>>>> displayed
    >>>>> in the cell?
    >>>>>
    >>>>> Sample cell actual text: A & C Hauling
    >>>>>
    >>>>> dim ven as String
    >>>>>
    >>>>> ven = me.Gridview1.SelectedRow.Cells(2).Text
    >>>>>
    >>>>> Result to ven variable is A &amp; Hauling
    >>>>>
    >>>>> Thanks
    >>>>>
    >>>>> John
    >>>>
    >>>>
    >>>
    >>>
    >>>

    >>

    >
    >
    >
     
    Steven Cheng[MSFT], Oct 17, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Mueller
    Replies:
    3
    Views:
    33,063
    Stefan Mueller
    Jul 23, 2006
  2. Charly
    Replies:
    1
    Views:
    1,751
    hkjaja
    Feb 20, 2010
  3. Replies:
    2
    Views:
    1,102
    Ingo Menger
    May 31, 2007
  4. rvino
    Replies:
    0
    Views:
    4,668
    rvino
    Aug 14, 2007
  5. Joel Finkel

    Cells[].Text or Cells[].Controls[0]

    Joel Finkel, Sep 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    313
    Joel Finkel
    Sep 1, 2003
Loading...

Share This Page