TableCell.Text property is ignored if there are child controls

I wanted to dynamically create content of ASP.NET TableCell control. It should have some text and image.
I've tried to use the code

cell.Text = "Text";
cell.AddControls(imgControl);
 

But the text wasn't shown. The reason is that if TableCell has child controls, the text value is ignored during rendering. See TableCell.RenderContents in Reflector.

The valid way is the following:
Label lbl=new Label();
lbl.Text=text;
cell.Controls.Add(lbl);
cell.AddControls(imgControl).

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
«January»
SunMonTueWedThuFriSat
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789