Use mshtml and webbrowser to generate beautiful and practical winform applicationsProgram(By lostinet.
In axshdocvw. the axwebbrowser control loads a SELECT statement in the HTML file. to Dynamically Retrieve the list content from the database and put it in the SELECT statement, the select option must display the Department name, when selecting an option, you can pass the corresponding department number through
Mshtml. ihtmlelement2 elesel = (mshtml. ihtmlelement2) Doc. All. Item ("selname", null );
(Mshtml. htmlselectelementclass) elesel). innerhtml = "<option...>... </option> ";
No.
Try to use JavaScript on the page to perform this operation:
1. Define a public string variable in the winform form to be passed to the HTML document. The required format is "department name 1 # Department name 2 #......; Department No. 1 # Department No. 2 #......", That is, the first half of the string (strmoreunit) is divided into the department name, the second half is the department number, the Department name and the Department number are separated, the Department name and department number are separated. Such a string can be easily constructed by loops in the documentcomplete event of the axshdocvw. axwebbrowser control (system. Text. stringbuilder should be used to improve efficiency ).
2. define functions in the loaded HTML file:
Function setmoreunit ()
{
VaR strmoreunit = Document. mainform. setmoreunit ();
If (strmoreunit! = "")
{
VaR call = strmoreunit. Split (";");
VaR cname = call [0]. Split ("#");
VaR cid = call [1]. Split ("#");
For (I = 0; I <cname. length; I ++)
{
VaR ooption = Document. createelement ("option ");
Selou. Options. Add (ooption );
Ooption. innertext = cname [I];
Ooption. value = CID [I];
}
}
}