为了账号安全,请及时绑定邮箱和手机立即绑定

绑定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 关注
  • 446 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信