select控制項綁定資料,預設選中項,select控制項綁定選中

來源:互聯網
上載者:User

select控制項綁定資料,預設選中項,select控制項綁定選中

設定 “select”屬性即可,如:

<span style="font-size:18px;"><select class="fl" id="search_CityId" name="search_City"><option value="0" selected="selected">不限</option></select></span>

擼主用的是springMVC架構,後台將select需要繫結資料,放入model,model.addAttribute("dataList", dataList);

JSP頁面用forEach迴圈即可搞定:

<span style="font-size:18px;"><li class="clear"><label class="fl">產品:<em style="color:red">*</em></label><select id="crt_Product" tabindex="10"><c:forEach items="${dataList }" var="data" ><option value="${data}" >${data}</option></c:forEach></select></li></span>







從資料庫讀取的資料作為Select的預設選中項怎實現?

//判斷Select預設值
function CheckSel(Voption,Value)
{
var obj = $GetID(Voption);
if (obj)
{
for (var i=0;i<obj.length;i++){
if (obj.options[i].value==Value){
obj.options[i].selected=true;
break;
}
}
}
} CheckSel("priority",1)你的option 裡面的value要指定為1才行你的現在是沒有值的~
 
更改時,從資料庫中查出來的值怎設定到select控制項中

DropDownList1的綁定資料
this.DropDownList1.DataSource = 資料來源
this.DropDownList1.DataValueField = 只綁定欄位
this.DropDownList1.DataTextField = "顯示綁定欄位";
this.DropDownList1.DataBind();
this.DropDownList1.Items.Insert(0, new ListItem("Select", "/"));

Programme.SelectedValue 這個是選定的值 還有id什麼的 text什麼的
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.