1

I have a DropDownList as a TemplateField in a DetailsView. I want to populate this DropDownList with all possible options that will be pulled from one SqlDataSource while assigning the selected value of the DropDownList to the current value coming from the SqlDataSource that the DetailsView is bound to. So something like:

<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>

1 Answer 1

1

You can assign the DataSourceID of the DropDownList to the data source that populates the options, and then assign the SelectedValue to the current value from the data source bound to the DetailsView:

<asp:DropDownList ID="Serial" DataSourceID="SqlDataSource#"
    DataValueField="..." DataTextField="..."
    SelectedValue='<%#Bind("MYFIELDNAME")%>'>
</asp:DropDownList>

Where MYFIELDNAME comes from the data source bound to the DetailsView representing the current value for that record.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.