Mshtml: javascript adds option for select in the HTML file

Source: Internet
Author: User

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];

}

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.