Databound dropdownlist: selectedValue from a second datasource?

G

Guest

I'm finding articles all over the place saying how to bind a dropdownlist to
an objectdatasource or sqldatasource in .NET 2.0/VS2005 but nothing that says
how to get the selected value from another datasource.

Here's the scenario.
I'm essentially loading an order for a client. There is a dropdownlist
(ddlClient) with a list of clients (populated by a sqldatasource). Each
ListItem's value is the clientID.

<asp:SqlDataSource ID="sqlClientSearch" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
SelectCommand="proc_ClientLookup" SelectCommandType="StoredProcedure"
ProviderName="System.Data.SqlClient">
<SelectParameters />
</asp:SqlDataSource>

I need to load the Order object (from another datasource) and then select
the clientID on the Order in ddlClient. I tried doing this in the code
behind but when the Page_Load() runs, the binding of the ddlClient hasn't
occurred yet so it contains no ListItems (and thus
ddlClient.Items.FindByValue(clientID) doesn't work).

So I'm presuming I need to create a second data source in the aspx page that
loads the individual order record like so:
<asp:SqlDataSource ID="sqlOrderSearch" runat="server" ConnectionString="<%$
ConnectionStrings:MyConnectionString %>"
SelectCommand="proc_OrderLookup" SelectCommandType="StoredProcedure"
ProviderName="System.Data.SqlClient">
<SelectParameters> <asp:QueryStringParameter Name="OrderID"
QueryStringField="OrderID" Type="Int32" />
</asp:SqlDataSource>

But what I can't figure out is how to tell the dropdownlist ddlClient to
use the clientID field in the sqlOrderSearch datasource as the selected value.

Can someone please assist?

Thanks in advance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top