how to get away with   and & while reading column value of gridview

Posted by Laghaterohan under C# on 9/22/2013 | Points: 10 | Views : 5009 | Status : [Member] | Replies : 4
Hello,

I have binded a gridview, wherein sometimes I get values for some columns as Blank. While reading the text from these blank columns I get text of these blank columns as  
and hence my validation to check if the column value is null or empty fails.

I need to know how to prevent this? ie. if the column value is blank, then I should get it as empty string only while reading the text from this column and not  



Please help...

Best Regards,
Rohan Laghate



Responses

Posted by: Bandi on: 9/23/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Two approaches to resolve the issue:
1) Raplace &nbps; with Empty string while retrieving value from gridview cell
txtComment.Text = row.Cells[3].Text.Replace(" ", "");


2) In the validation itself check for &nbps;
If ( row.Cells[3].Text == "&nbps;") 

{
//Your Code here
}


Reference:
http://stackoverflow.com/questions/3737867/prevent-empty-gridview-data-from-populating-nbsp-into-textbox

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nismeh on: 9/23/2013 [Member] Starter | Points: 25

Up
0
Down
You need to check your text is '&nbps' or not. If it is than you can set is null...

as in previous example

If ( row.Cells[3].Text == "&nbps;") 


{
// Make Your check/set variable is null
}


You can even go through string operation by replacing text.

IT KNOWLEDGE IS APPLIED KNOWLEDGE
So Just Do It

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rimi1289 on: 9/23/2013 [Member] Starter | Points: 25

Up
0
Down
CODE BEHIND
Trim(Replace(.Rows(iRow).Cells(iCol).Text, " ", ""))


JAVASCRIPT
.replace(/,/g, '')


Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Carlitos12 on: 2/23/2017 [Member] Starter | Points: 25

Up
0
Down
use this:
Server.HtmlDecode()


txtComment.Text = Server.HtmlDecode(row.Cells[14].Text);


it handles not only spaces, but also other conversions like for ampersands(&), etc.

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response