Select binding example in the drop-down box and select example in the drop-down box

Source: Internet
Author: User

Select binding example in the drop-down box and select example in the drop-down box

Bind text based on text

var locationCity = productViewObj.Product.LocationCity; var countCity = $("#slCity option").length; for (var i = 0; i < countCity; i++) { if ($("#slCity").get(0).options[i].text == locationCity) { $("#slCity").get(0).options[i].selected = true; break; } }

Bind value by value

var deliveryTemplateID = productViewObj.Product.DeliveryTemplateID; var deliveryCount = $("#deliverySelect option").length; for (var i = 0; i < deliveryCount; i++) { if ($("#deliverySelect").get(0).options[i].value == deliveryTemplateID) { $("#deliverySelect").get(0).options[i].selected = true; break; } }


How to bind data from SELECT to the drop-down list

Let's talk about the first problem first. If the problem I just fixed for you is correct, please post it.
Let's talk about this problem. I don't need to talk about it when I connect to the database.
After connecting to the database:
DropDownList1.DataSource = ds. Tables [0];
DropDownList1.DataTextField = "GroupNaId ";
DropDownList1.DataValueField = "GroupID ";
DropDownList1.DataBind ();

The code used by js to bind a value to the select drop-down box is as follows: the value is obtained but cannot be bound to the drop-down box.

Your select assignment is incorrect.
You can try this:

Var sel = document. getElementById ("cl_types ");
Var opt = new Option ("A", "11 ");
Sel. options. add (opt );
Var opt1 = new Option ("B", "11 ");
Sel. options. add (opt1 );
Opt1.selected = true;
Var opt2 = new Option ("C", "11 ");
Sel. options. add (opt2 );

There are still problems HI me ~

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.