Databound dropdownlist: selectedValue from a second datasource?

Discussion in 'ASP .Net' started by =?Utf-8?B?YW55ZW9uZQ==?=, Dec 19, 2005.

  1. 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!
     
    =?Utf-8?B?YW55ZW9uZQ==?=, Dec 19, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Micallef
    Replies:
    0
    Views:
    648
    Mark Micallef
    Apr 5, 2007
  2. rodchar
    Replies:
    0
    Views:
    397
    rodchar
    Nov 26, 2007
  3. Manu
    Replies:
    0
    Views:
    172
  4. Mark Micallef
    Replies:
    0
    Views:
    217
    Mark Micallef
    Apr 5, 2007
  5. Lagrange
    Replies:
    1
    Views:
    569
    Lagrange
    Jan 17, 2009
Loading...

Share This Page