如何用空td替换元素的td

时间:2011-01-13 12:11:01

标签: c# asp.net

嗨,我有一个像

这样的结构
<td valign="top" style="width:150px;" > 
     <img alt="<recipetitle/>" src="http://<rootweburl/>/photos/recipes/Large/<recipephotoname/>" alt="logo" style="float:left;"/> 
</td>

其中<recipetitle/><recipephotoname/>是参数并且可以更改。我想用空td替换此td。我将如何在C#中执行此操作

1 个答案:

答案 0 :(得分:3)

您需要使表格单元格成为服务器端控件,以便您可以从后面的代码访问它。

<table>
    <tr>
        <td valign="top" style="width:150px;" runat="server" id="tdToBeCleared">
            <img alt="<recipetitle/>" src="http://<rootweburl/>/photos/recipes/Large/<recipephotoname/>" alt="logo" style="float:left;"/>  
        </td>         
    </tr>
</table>

在codebehind中,您可以更改控件的innerhtml。如果要清除内容,只需使用以下行:

tdToBeCleared.InnerHtml = string.Empty;

编辑 只需将td更改为与您的示例匹配,您只需复制并粘贴即可。

相关问题