locked
Launch event when data source changes RRS feed

  • Question

  • User-829096311 posted

    Hi
    How do I execute code when the data in the data source changes
    I use this code, but nothing happens.

    <asp:SqlDataSource ID="dsDetail" runat="server" ConnectionString="<%$ ConnectionStrings:SiteConnectionString %>" SelectCommand="SELECT * FROM MyTable">
                <SelectParameters>
                    <asp:ControlParameter ControlID="ListView1" Name="id" PropertyName="SelectedValue" />
                </SelectParameters>
            </asp:SqlDataSource>
    
     Protected Sub ٍSqlDataSource1_Selecting(sender As Object, e As SqlDataSourceSelectingEventArgs) Handles SqlDataSource1.Selecting
           ' some code here
     End Sub

    Thank you in advance

    ..

    Saturday, November 11, 2017 1:03 PM

All replies

  • User753101303 posted

    Hi,

    "when the data in the data source changes" is a  bit vague. According to what you are showing it seems you want to refresh your data when the user is selecting another value in a drop down ? The drop down should use Autopostback="true" to trigger the postback automatically and your query should use this parameter in the WHERE clause to show filtered data.

    Or do you really mean that you want to refresh this page if someone else changed the underlying data? Then do a search for "SignalR" and "SqlDependency".

    Monday, November 13, 2017 2:04 PM
  • User-829096311 posted

    Thank you for reply

    As in this  MSDN walkthrough Displaying Master/Detail Data on the Same Page

     I want to delete  detail data control

    and handle the event  that make detail data control change when SelectedValue change

    Monday, November 13, 2017 6:45 PM
  • User753101303 posted

    So I believe you want something such as :

        <asp:DropDownList runat="server" ID="ListView1" DataSourceID="ddlSource" AutoPostBack="true" DataTextField="Text" DataValueField="Id">
        </asp:DropDownList>
        <asp:SqlDataSource ID="ddlSource" runat="server" ConnectionString="<%$ConnectionStrings:SiteConnectionString %>" SelectCommand="SELECT Text,Id FROM MyTable" />
         <asp:SqlDataSource ID="dsDetail" runat="server" ConnectionString="<%$ ConnectionStrings:SiteConnectionString %>" SelectCommand="SELECT * FROM MyTable WHERE Id=@id">
                <SelectParameters>
                    <asp:ControlParameter ControlID="ListView1" Name="id" PropertyName="SelectedValue" />
                </SelectParameters>
            </asp:SqlDataSource>
        <asp:DetailsView runat="server" DataSourceID="dsDetail" DataKeyNames="Id">
        </asp:DetailsView>
    

    The drop down is configured to trigger automatically a postback when another value is selected.
    The detail view is configure to get data from a SQL statement that uses the value for this control to select what to show.

    As a result if you select a value from the drop down, the page is refreshed and shows the selected row in the the detail control. I don"t have any code at all in my code behind.

    Monday, November 13, 2017 8:45 PM