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 ~