I need to perform some string manipulation to a columns contents in a GridView, and I'm using the DataBinding event for the template field for this. I'm converting all Environment.NewLine's to
's for outputting.Here is the code:
protected void Label1_DataBinding(object sender, EventArgs e)
{
Label lb = (Label)sender;
lb.Text.Replace(Environment.NewLine, "<br />");
}
But it doesn't work. But interestingly, if I assign it to a string like so:
protected void Label1_DataBinding(object sender, EventArgs e)
{
Label lb = (Label)sender;
string outputtest = lb.Text.Replace(Environment.NewLine, "<br />");
Response.Write(outputtest);
}
It writes the correct, newly modified, string at the top - but why isn't it feeding back to the g开发者_如何学Gorid view?
Replace doesn't actually set any value - it only returns the replacement string. Try:
protected void Label1_DataBinding(object sender, EventArgs e)
{
Label lb = (Label)sender;
lb.Text = lb.Text.Replace(Environment.NewLine, "<br />");
}
精彩评论