亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

綁定DropDownList的SelectedIndex

綁定DropDownList的SelectedIndex

慕的地8271018 2018-12-07 01:14:49
DropDownList是放在FormView上的,后者綁定到一個數據源. DropDownList的Items是代碼設置的,我想把數據源中對應的值綁定到它的SelectedIndex屬性, 代碼如下: <asp:FormView         ID="FromView1"        DataKeyNames="ID"        DataSourceID="myDataSource"        AllowPaging="true"        runat="server">       <ItemTemplate>       <h3><%# Eval("Date") %></h3>       <asp:TextBox        ID="txtDate"        Text='<%# Bind("Date") %>'        runat="server" />       <asp:DropDownList ID="DropDownList1" runat="server">(如何綁定?)                            <asp:ListItem>IC</asp:ListItem>                            <asp:ListItem>1</asp:ListItem>                            <asp:ListItem>2</asp:ListItem>                            <asp:ListItem>3</asp:ListItem>                            <asp:ListItem>4</asp:ListItem>                            <asp:ListItem>5</asp:ListItem>                            </asp:DropDownList>       </ItemTemplate> </formview> <asp:ObjectDataSource            ID="myDataSource"            TypeName="ShanShan.myClass"            SelectMethod="SelectAll"            UpdateMethod="Update"            InsertMethod="Insert"            DeleteMethod="Delete"            runat="server" >       </asp:ObjectDataSource> DropDownList 能像TextBox那樣直接Bind綁定么? 望不吝賜教!
查看完整描述

3 回答

?
繁星點點滴滴

TA貢獻1803條經驗 獲得超3個贊

不可以實現,因為TextBox的Text屬性有Bindable(true, BindingDirection.TwoWay) Attribute;而DropdownList的SelectedIndex沒有指定此Attribute;所以不可做數據綁定。 你可以用反射工具看看源代碼實現。
查看完整回答
反對 回復 2019-01-21
?
慕森王

TA貢獻1777條經驗 獲得超3個贊

這樣行不行
查看完整回答
反對 回復 2019-01-21
?
手掌心

TA貢獻1942條經驗 獲得超3個贊

不行,只能通過后臺代碼實現
查看完整回答
反對 回復 2019-01-21
?
富國滬深

TA貢獻1790條經驗 獲得超9個贊

查看完整回答
反對 回復 2019-01-21
  • 3 回答
  • 0 關注
  • 506 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號