Home > Forum > C# > How to change html encoded characters from gridview cells in c#?

How to change html encoded characters from gridview cells in c#?

by Thamil   on Aug 20, 2014   Category: C#  |  Views: 1812    |  Points: 5   |  Gold 
  Reply
Actually I’m reading the each row/cell from gridview by using LINQ and store into list and update into the database from list. See the below code.
//Read rows from gridview and store into List.
List<EmpList> EmpListDetails = (from drow in gvEmp.Rows.Cast<GridViewRow>()
select new EmpList()
{
Name = drow.Cells[2].Text,
nationality = drow.Cells[3].Text,
passportNo = drow.Cells[4].Text,
Address = drow.Cells[5].Text,
Contact = drow.Cells[6].Text,
}
).ToList();

Gridview-gvEmp loading the data from database, when you update the same data back to the database from gridview , it’s throwing error like “value too large for…” because of address value exceeds maximum size limit - due to space. Wherever manually added the space in the address, gridview encoded the (“ ”) space as '& #160 ;'. Same value “ & #160 ;” would be assigned in the List as well. So this “& #160;” character needs to be changed as “ ” space again while assigned values into List.

Please advise.


Bookmark and Share:
 
  User Reply  | Ask a question  |   Reply 
  Re :How to change html encoded characters from gridview cells in c#?   
by Thamil
on Aug 20 2014 2:44AM
Points : 10
Gold 
I have resolved this issue by using Server.HtmlDecode method, this method decoded the value “& #160;” to “ ” actual space and database update is happening without any issue. See the below code.
List<EmpList> EmpListDetails = (from drow in gvEmp.Rows.Cast<GridViewRow>()
select new EmpList()
{
Name = drow.Cells[2].Text,
nationality = drow.Cells[3].Text,
passportNo = drow.Cells[4].Text,
Address = Server.HtmlDecode(drow.Cells[5].Text),
Contact = drow.Cells[6].Text,
}
).ToList();

Recent Post

Latest Posts

1 3D model and 2D View New! Forum