locked
Does SQLDataSource1 loads before SQLDataSource2 and so on? RRS feed

  • Question

  • User-758504035 posted

    I have a DropDownList which controls DetailsView control(using the <SelectParameters><ControlParameter>.....)

    Previously I had DropDownList bound to a SQLDataSource2 and DetailsView to SQLDataSource1, which resulted in DetailsView being empty the first time the page loaded.

    Next(after wasting about 5 hours) I tried the opposite (DropDown to SQLDS1 and DetailsView to SQLDS2) and now its working correctly.

    Any particular reason for this behaviour?

    Wednesday, March 1, 2017 8:16 AM

All replies

  • User527778624 posted

    Hi,

    Control parameter on DataSouce depends on particular control (ddl), when its value changes, only then DataSource fetches data based on value and applies it to depending control (listview).

    Wednesday, March 1, 2017 10:06 AM
  • User-758504035 posted
    Thanks for telling me something which I already know.
    Wednesday, March 1, 2017 10:20 AM
  • User-707554951 posted

    Hi ZaidARKhan

    Any particular reason for this behaviour?

    I didn't think that the reason of your problem is related to the SQLDataSource1 or SQLDataSource2;

    Because I use the following code to test.

       <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" 
                DataTextField="CategoryName" DataValueField="CategoryID" 
               AutoPostBack="true" ></asp:DropDownList>
             
             <asp:DetailsView ID="DetailsView1" runat="server"  DataSourceID="SqlDataSource1" AutoGenerateRows="false">
        <Fields>
            <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" HeaderStyle-Font-Bold="true" />
            <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" HeaderStyle-Font-Bold="true" />
            <asp:BoundField DataField="Description" HeaderText="Description" HeaderStyle-Font-Bold="true" />
        </Fields>
    </asp:DetailsView>
    
             <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories] WHERE  CategoryID = @CategoryIDParam">
         <SelectParameters>
             <asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue" Name="CategoryIDParam"/>
             
         </SelectParameters>
             </asp:SqlDataSource>
          <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]"></asp:SqlDataSource>
         

    The output after when the first time the page loaded:

    So, I think that it perhaps because you change you code in that 5 hours.

    Best Regards

    cathy

    Thursday, March 2, 2017 7:02 AM