Link to home
Start Free TrialLog in
Avatar of Member_2_3703398
Member_2_3703398Flag for United Kingdom of Great Britain and Northern Ireland

asked on

C# String Manipulation

Hi,

I have a GridView that contains a comapny name. The problem is that although the GridView displays the text correct e.g. 'Smtih & Sons', when my code gets the text from the cell, i am returned 'Smith & Sons'.

How can I get it to return what I can see on the screen?

Thanks.
protected void GridViewBrowseResults_RowCommand(object sender, GridViewCommandEventArgs e)
{
  if (e.CommandName.Equals("ViewFile"))
  {
    int index = Convert.ToInt32(e.CommandArgument);
    string myRootDir = BrowseType;
    string myCompanyDir = GridViewBrowseResults.Rows[index].Cells[1].Text;
    string mySubDir = myListDirectoryMap[index].File_Folder;
    string myFileName = GridViewBrowseResults.Rows[index].Cells[3].Text;
    myToolBox.SetAccessPath(myRootDir, myCompanyDir, mySubDir, myFileName);
    }
}
 
 
Watch Results:
 
index	                      0                   	int
myRootDir	                      "quotation"    	string
myCompanyDir	"Smith & Sons"	string
mySubDir	                     "12008"         	string
myFileName	                     "FQ-0000012008-0"	string

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of MaxOvrdrv2
MaxOvrdrv2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeah, the above will work perfectly; however, be aware that the ampersand (&) is not the only 'trick' character. There are a few more, as follows:

<   >
>   <
"    &quot;
&   &amp;
'    &apos; // Not always, though!

That's all I can think of off the top of my head, for now.
Oh great, this site's system is even too ghetto to handle itself, lol. The first two lines are supposed to say

<  & gt;
>  & lt;

No spaces between the letters and the & though
Avatar of MaxOvrdrv2
MaxOvrdrv2

my post above should handle all of the characters...
Setting BoundField.HtmlEncode to false will do the trick as well.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.htmlencode.aspx

Avatar of Member_2_3703398

ASKER

Hi,

Thank you all for the posts. Tetorvik, I tried your suggestion but unfortunately, I had no success with it.
Thank you for the code. Works like a dream.