替换c#中的子节点

时间:2016-11-09 11:28:27

标签: asp.net string c#-4.0

我有一个像

这样的字符串HTML代码
 <table id='topInfoBar' style=" width: 100%;" cellspacing='0' border='0'>
 <Tr>
 <td id='lockOrder' clientidmode='static'  style="text-align:Right;color:black;font-weight:bold">  
 <img src='.../images/locked.gif' alt='This order is locked' title='This order is locked!' />
 </td>
 </Tr>
 </table>

我想检查字符串中是否存在id 'lockOrder',如果是,则要替换img节点,即

<img src='.../images/locked.gif' alt='This order is locked' title='This order is locked!' />

 <i class="fa fa-search fa-2x cursorpointer"  title="This order is locked"></i>

希望在c#中完成。

1 个答案:

答案 0 :(得分:1)

使用属性Visible并在

中更改

HTML

<table id='topInfoBar' style="width: 100%;" cellspacing='0' border='0'>
    <Tr>
        <td id='lockOrder' clientidmode='static' style="text-align: Right; color: black; font-weight: bold">
            <img src='.../images/locked.gif' alt='This order is locked' title='This order is locked!' runat="server" id="img"/>
            <i class="fa fa-search fa-2x cursorpointer" title="This order is locked" runat="server" id="i" Visible="False"></i>

        </td>
    </Tr>
</table>

CodeBehind C#

            if (true)
            {
                img.Visible = false;
                i.Visible = true;
            }