我在DetailsView中有一个DropDownList作为TemplateField。我想在DropDownList中填充所有可能的选项,这些选项将从一个SqlDataSource中提取,同时将DropDownList的选定值分配给来自DetailsView绑定的SqlDataSource的当前值。如下所示:
<asp:DetailsView DataSourceID="SqlDataSource1">
<asp:TemplateField>
<asp:DropDownList ID="Serial">
/* Here is where I need to bind the dropdown to data source 2 so that All serials are available while selecting it's current value from data source 1.
</asp:TemplateField>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1"
SelectCommand = "Select SerialNumber From Equipment Where EquipID = @EquipID">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" DefaultValue=""
Name="EquipID" PropertyName="SelectedDataKey.Values[EquipID]" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2"
SelectCommand = "Select SerialNumber From Equipment">
</asp:SqlDataSource>
答案 0 :(得分:1)
您可以将DataSourceID
的{{1}}分配给填充选项的数据源,然后将DropDownList
分配给绑定到{{的数据源的当前值1}}:
SelectedValue
DetailsView
来自绑定到<asp:DropDownList ID="Serial" DataSourceID="SqlDataSource#"
DataValueField="..." DataTextField="..."
SelectedValue='<%#Bind("MYFIELDNAME")%>'>
</asp:DropDownList>
的数据源,表示该记录的当前值。