开发者

How to trim html tags from text in asp.net grid view?

开发者 https://www.devze.com 2023-03-20 18:18 出处:网络
I have used asp.net ajax html editor and i s开发者_Python百科aved data in database. But now i want to retrieve it and show it in grid view. But when i retrieve that, it also shows those html tags (gen

I have used asp.net ajax html editor and i s开发者_Python百科aved data in database. But now i want to retrieve it and show it in grid view. But when i retrieve that, it also shows those html tags (generated by asp.net ajax editor). So, i want to trim those tags and show plain text in grid view. How do i do that? Thanks


Go to you db and look, how it is saved. Maybe it is save encoded. If it is not the case, you can use some simple regex to remove all those tags.

<[^<]+?>

This shows you just plain text and removes all Tags


To stripe the html tags from text you can utilize the

RegEx.Replace("str","Pattern","replacementstring "); method which there exist in System.Text.RegularExpressions namespace

for example

 Plain_Body = Regex.Replace(txtBody.Text, @"<[^>]*>", string.Empty);

here i am replacing the html specific characters with String.Empty or "" you can add additional characters if you wish to pattern like @"<[^>]*>" and spaces(&nbsp) and Ampersand(&amp) etc

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号