将字符串分配给 HtmlElement 对象的 InnerHtml
我尝试在 HTML 中填充“Select”元素,同时在我自己的浏览器中的 C# 应用程序中打开该元素。所以我这样做了:
DataTable dt = new DataTable();
HtmlElement States = webBrowser1.Document.GetElementById("Select1");
da.Fill(dt);
States.InnerHtml = "";
for (int i = 0; i < dt.Rows.Count; i++)
{
string head = String.Format(@"<option Value=""{1}"">",
dt.Rows[i]["Code"].ToString());
string body = String.Format("{0}</option>", dt.Rows[i]["Name"].ToString());
string tag = head + body;
States.InnerHtml =tag;
}
但令人惊讶的是,当我期望结果是这样的时候,
< option Value="aNumber">testString<\option>
我看到了这个:
testString<\option>
当我努力编写预期的字符串时,我在这里看到了同样的问题。最后,我在字符串的第二个字符中插入了一个空格。因此我写了 < option>
而不是这里的 。我对要传递给元素的
InnerHtml
属性的字符串做了同样的事情。但不幸的是它没有起作用。
I try to fill up a "Select" element in my HTML while it's open on my own browser in a C# application. So i did this:
DataTable dt = new DataTable();
HtmlElement States = webBrowser1.Document.GetElementById("Select1");
da.Fill(dt);
States.InnerHtml = "";
for (int i = 0; i < dt.Rows.Count; i++)
{
string head = String.Format(@"<option Value=""{1}"">",
dt.Rows[i]["Code"].ToString());
string body = String.Format("{0}</option>", dt.Rows[i]["Name"].ToString());
string tag = head + body;
States.InnerHtml =tag;
}
But surprisingly when I expect to result be something like this
< option Value="aNumber">testString<\option>
I see this:
testString<\option>
I saw the same problem here when I was struggling to write the expected string. Finally I inserted a blank space to the second char on my string. Thus I worte < option>
instead of <option>
in here. I did same for that string which I want to pass to the InnerHtml
property of my element. But unfortunately it didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不应该
是这个吗?
Shouldn't this
be this?