DropDownList是放在FormView上的,后者綁定到一個數(shù)據(jù)源.
DropDownList的Items是代碼設(shè)置的,我想把數(shù)據(jù)源中對應(yīng)的值綁定到它的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綁定么?
望不吝賜教!
綁定DropDownList的SelectedIndex
慕的地8271018
2018-12-07 01:14:49