开发者

Setting label text in DataBinding in a GridView (ASP.NET/C#)

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 />");
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜