本文整理汇总了C#中System.Windows.Forms.HtmlDocument.CreateElement方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDocument.CreateElement方法的具体用法?C# HtmlDocument.CreateElement怎么用?C# HtmlDocument.CreateElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.HtmlDocument
的用法示例。
在下文中一共展示了HtmlDocument.CreateElement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisplayCustomersTable
private void DisplayCustomersTable()
{
DataSet customersSet = new DataSet();
DataTable customersTable = null;
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Customers", "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;");
sda.Fill(customersTable);
customersTable = customersSet.Tables[0];
if (webBrowser1.Document != null)
{
HtmlElement tableRow = null;
HtmlElement headerElem = null;
HtmlDocument doc = webBrowser1.Document;
HtmlElement tableElem = doc.CreateElement("TABLE");
doc.Body.AppendChild(tableElem);
HtmlElement tableHeader = doc.CreateElement("THEAD");
tableElem.AppendChild(tableHeader);
tableRow = doc.CreateElement("TR");
tableHeader.AppendChild(tableRow);
foreach (DataColumn col in customersTable.Columns)
{
headerElem = doc.CreateElement("TH");
headerElem.InnerText = col.ColumnName;
tableRow.AppendChild(headerElem);
}
// Create table rows.
HtmlElement tableBody = doc.CreateElement("TBODY");
tableElem.AppendChild(tableBody);
foreach (DataRow dr in customersTable.Rows)
{
tableRow = doc.CreateElement("TR");
tableBody.AppendChild(tableRow);
foreach (DataColumn col in customersTable.Columns)
{
Object dbCell = dr[col];
HtmlElement tableCell = doc.CreateElement("TD");
if (!(dbCell is DBNull))
{
tableCell.InnerText = dbCell.ToString();
}
tableRow.AppendChild(tableCell);
}
}
}
}