Andha
Andha

Reputation: 917

Replacing <br> tag in asp multiline textbox

I'm working with textbox in a datagrid. Before saving the data into the database, I replace the newline with <br> by using following script :

description.Replace(Environment.NewLine, "<br>")

Working fine, it's replacing the newline with <br>. Then I need to fetch the data into the textbox again for editing. I've tried to replace the <br> with newline by using following script :

data.description = ((TextBox)dgrid.Items[i].FindControl("description")).Text;
data.description = data.description.Replace("<br>", "\r\n");

But it's not working, do you guys have any solutions for this ?

Upvotes: 0

Views: 2319

Answers (1)

Doozer Blake
Doozer Blake

Reputation: 7797

You're not setting the Text value back, you're changing data.description. Try changing it to something like

Textbox txt = ((TextBox)dgrid.Items[i].FindControl("description"));
txt.Text = txt.Text.Replace("<br>", Environment.NewLine);

There's likely a better place to do this, but without seeing everything, it's hard to say.

Upvotes: 2

Related Questions