如何在c#中动态添加文本到跨度控件

时间:2012-08-09 05:40:35

标签: c# asp.net

net c#。我正在使用占位符,并动态添加跨度到占位符。如何在c#asp.net中动态添加文本?​​

2 个答案:

答案 0 :(得分:4)

你可以使用html泛型控件,就像这样

var yourspan = new HtmlGenericControl("span");
span.InnerHtml = "the text inside your span ";
yourspan.Attributes["id"] = "yourspan";
pannel.Controls.Add(span);

http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlgenericcontrol.aspx

答案 1 :(得分:2)

Make table runat =“server”

 <table id="myTable" runat="server" width="100%">    
    <tr>
    <td>
    <span></span>
    </td>
    </tr>

    </table>

    **In code behind u do like this** 
 myTable.Rows[1].Cells[0].InnerHtml = "<span id="1">" + YOURTEXT+ "</span>";