日期:2014-05-18  浏览次数:20755 次

WebBrowser控件使用问题
我通过     HtmlElement   trHtml   =   htmlDoc.All[ "IncrProdTab "]     从     WebBrowser     里面获取以下代码段,现在我想在以下代码段里添加内容,并WebBrowser里显示最新的内容,但是我通过trHtml.InnerHtml=新内容却出现异常,请问我该怎么办呢?


<table   id= "IncrProdTab ">
  <TBODY>
   <TR   id=IncrProdRow_0>
     <TD>
    <INPUT   title= " "   value=A5   name=incrProd.prodClassCode>
    <INPUT   title= " "   value=呼叫转移   name=incrProd.prodClassName>
     </TD>
   </TR>
   <TR   id=IncrProdRow_1>
    <TD>
     <INPUT   title= " "   value=A8   name=incrProd.prodClassCode>
     <INPUT   title= " "   value=呼出限制   name=incrProd.prodClassName>
    </TD>
   </TR>

                    ★★★我要在这里添加新的内容。

  </TBODY>
</table>

 


★★★这是要添加的内容:
<tr   id= "IncrProdRow_2 ">
  <td>
    <input   type= "text "   name= "incrProd.prodClassCode "   value= "B8 ">
    <input   type= "text "   name= "incrProd.prodClassName "   value= "来电显示 ">
  </td>
</tr>


------解决方案--------------------
//参考如下代码:

//项目中添加Micrsoft.mshtml引用
using mshtml;

private void button1_Click(object sender, EventArgs e)
{
HtmlDocument htmlDoc = webBrowser1.Document;
HTMLTable htmlTable = htmlDoc.All[ "IncrProdTab "].DomElement as HTMLTable;
HTMLTableRow htmlRow = htmlTable.insertRow(htmlTable.rows.length) as HTMLTableRow;

htmlRow.id = "id=IncrProdRow_2 ";
HTMLTableCell htmlCell = htmlRow.insertCell(0) as HTMLTableCell;
htmlCell.innerHTML =
@ " <td> " +
@ " <input type= " "text " " name= " "incrProd.prodClassCode " " value= " "B8 " "> " +
@ " <input type= " "text " " name= " "incrProd.prodClassName " " value= " "来电显示 " "> " +
@ " </td> ";
}

------解决方案--------------------
使用HTMLTable,将htmlDoc.All[ "IncrProdTab "]转化成HTMLTable,然后使用新建一行,并插入你的内容即可。