onSelected in SqlDataSource not working RRS feed

  • Question


    Hi there,


    I have a onSelected in my SCartSource (SqlDataSource) which points to a Sub called Get_Rows in Get_Rows it would determine weather to make a Label visible if there are no records in the database.


    Even though the IF statement i have within the Get_Rows sub is perfect and it worked before up until i changed one page completely different to this one it suddenly stopped Sad

    I tested to see if the event is going to the Sub at all using a simple Message box which showed me it didn't. I am completely clueless on this on how to make it work, i've tried just about everything to get it going again without any luck.


    This is the code from the aspx page:


    <asp:Label id="ItemsNotFoundMSG" runat="server" Text="Shopping cart is empty" EnableViewState="False" Visible="False"

    Width="180px" Height="40px" BackColor="#E0E0E0" ForeColor="Red" BorderStyle="Solid" BorderWidth="1px" BorderColor="Silver"

    Style="margin-top:10px; padding:15px"/>

    <asp:Panel ID="Panel1" Width="550" runat="server" ForeColor="#FF0000" HorizontalAlign="Right">

    <asp:Label id="ErrorMSG" Text=" " EnableViewState="False" runat="server"/>



    <asp:SqlDataSource id="SCartSource"  runat="server" OnSelected="Get_Rows" SelectCommand="SELECT * FROM tbl_cart WHERE Order_ID=@Order_ID" UpdateCommand="UPDATE tbl_cart SET Book_Qty=@Book_Qty WHERE Order_ID=@Order_ID AND ISBN=@ISBN" DeleteCommand="DELETE FROM tbl_cart WHERE Order_ID=@Order_ID AND ISBN=@ISBN" ConnectionString="<%$ ConnectionStrings:BookDBConnectionString %>">


    <asp:ControlParameter Name="Order_ID" ControlId="lblOrder_ID" PropertyName="Text"/>



    <asp:ControlParameter Name="Order_ID" ControlId="lblOrder_ID" PropertyName="Text"/>



    <asp:ControlParameter Name="Order_ID" ControlId="lblOrder_ID" PropertyName="Text"/>




    This is the code from the VB page:


    Sub Get_Rows(ByVal Src As Object, ByVal Args As SqlDataSourceStatusEventArgs)

    If Args.AffectedRows = 0 Then

    ItemsNotFoundMSG.Visible = True

    End If

    MsgBox("if statement working!")

    End Sub



    Final Notes:

    I found that if i place the SCartSource above the ItemsNotFoundMSG it prints out the message "If statement working!" however, as soon as i add the Parameters it dies down immediately.



    Any help what so ever is appreciated, thank you in advance Smile


    Ohh and if anything more needs posting please let me know.

    Tuesday, February 19, 2008 4:17 AM


  • After constant trial and error i think i nailed it now. I could not resolve why onSelected did not work so i pulled a sneaky and somehow got it to work hehe ... sorta.


    Within the <SelectParameters> in the SCartSource it takes in the number or ID from the lblOrder_ID label. Simply i added a IF statement in the Page_Load sub to check if the label has anything in there if it doesn't make the ItemsNotFoundMSG label visible if it does well you get the picture Stick out tongue


    If lblOrder_ID.Text = "" Then

    CartEmptyMSG.Visible = True


    CartEmptyMSG.Visible = False

    End If


    Hope this helps anyone who has run into a similar problem Smile


    Damn thing has been plaguing me since yesterday morning lol

    Tuesday, February 19, 2008 9:06 AM