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.
Shouldn’t this
be this?