Hi..
In my asp project,i have used gridview to display data from database.I need to retrieve the data.One cell conatins data like 'A & B'.i.e data contains '&' symbol.But when i retrieve the data.I get the result as 'A &B'.So i cannot retrive the data from databse.How to solve this...I have used the code string a=gridview1.selectedRaw.cell[1].text.
Loading
Santhosh Kumar JayaramanPosted Jun 27, 2012, 4:50 AM
Santhosh Kumar JayaramanPosted Jun 27, 2012, 7:52 AM
Santhosh Kumar JayaramanPosted Jun 27, 2012, 7:51 AM
Ampersand & is a special character with different meaning in html. characters such as <,>,& will give those issues.
If you really want to get rid of it, you should use HtmlEncode when getting it from database and use htmldecode for the reverse i.e. saving it back to database.
The below link will be useful to understand more.
http://msdn.microsoft.com/en-us/library/w3te6wfz.aspx
You can also try
string a =Server.HtmlEncode(gridview1.selectedRaw.cell[1].text.ToString());
And for your question about company name with "amp". We replace only if the string contains "&" and not just for "amp", so its a very rare scenario where companyname have both & and ; character togehter.
Resmy RaviPosted Jun 27, 2012, 7:39 AM
Satyapriya NayakPosted Jun 27, 2012, 4:32 AM
Try this...
Remove it from database table.
UPDATE employee
SET EmpName = REPLACE(EmpName , '&', '&')
WHERE EmpName LIKE '%&%'
OR
lbl_name.Text = GridView1.SelectedRow.Cells[1].Text.ToString().Replace("&", "&");
Thanks