• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

Help with sql datasource selected event

I want to get the output parameter value from a sql datasource and use the value to display a meassage to the user.  It seems to skip the event all together for some reason.
  here is my codebehind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    SqlDataSource16.Select(DataSourceSelectArguments.Empty)
 End Sub

Protected Sub SqlDataSource16_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource16.Selected
        Dim iStatus As Integer
        iStatus = e.Command.Parameters("@outStatus").Value

        If iStatus > 0 Then
            Label2.Visible = True
            Label2.ForeColor = Drawing.Color.Red
            Label2.Text = "This acountis currently pending an update.  Please wait until the update is complete before making any account changes.  You may however make any datacorrections needed at this time."
            'make the form disabled so users cannot edit
            FormView3.Enabled = False
        End If
    End Sub

    Protected Sub SqlDataSource16_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles SqlDataSource16.Selecting
    End Sub

Does any one know why this is happening, or perhaps a better way to do this?  please provide vb code.

0
r_Shealy
Asked:
r_Shealy
  • 7
  • 5
  • 3
3 Solutions
 
Seven priceFull StackCommented:
not following, and out put parameter to the user.

Are your trying to wait for a value to change lets say from 1 to 0 as int inside your database. if is 1 then tell user this or if its 0 display user that.

Correct me if I am wrong.
0
 
r_ShealyAuthor Commented:
No, my sql datasource holds a stored procedure and the results from that stroed procedure will be an id number.  If there is an id number returned (i.e. > 0) then i need to display a message to the user, otherwise I do not want to display any message at all.  I am not waiting on anything to change.
Does that make sense?
0
 
Seven priceFull StackCommented:
You should return it in a Query string and pass the query string value to your parameter
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Seven priceFull StackCommented:
You can do a boolean function. Return a true or false value also. If return true do this otherwise do that.
0
 
r_ShealyAuthor Commented:
ok i know the code works because I use it another page, however for some reason the selected event is not firing , why????  or what other code can i use to accomplish the same thing?

0
 
Seven priceFull StackCommented:
Can you put a reponse.write to make sure your code behind is working or compiling. sometimes your project does not get compiled corretly or the function needs a handle. check to make sure that is not the problem since it has worked before.
0
 
r_ShealyAuthor Commented:
When I put a stop on the event in page load it does not go to the selected event.  The code itself is not executing but I dont know why. I dont see anything wrong, I was hoping that someone here would be able to tell me.
0
 
pschramaCommented:
Is the DataSourceID properly set to SqlDataSource16 on a databinding control on the aspx page?
Otherwise, I can see no reason why the events aren't getting fired.
0
 
r_ShealyAuthor Commented:
I think it is.  What is interesting is that when I step through the code and it comes to this point "SqlDataSource16.Select(DataSourceSelectArguments.Empty)" the code says there is not a matching event and closes without firing the selected event.  I have tried deleting the event and recreating it but that didn't work either.  But I will start from scratch again and see if something was wrong there, I will let you know.  
0
 
r_ShealyAuthor Commented:
Nope! I recreated everything from scratch but when I step through the code when it gets to

SqlDataSource16.Select(DataSourceSelectArguments.Empty)

it states that there is no source code available and doesn't execute the selected event.
Any ideas?
0
 
pschramaCommented:
Sounds like some kind of build problem, perhaps you can try setting the build type to release and back to debug, then rebuild.

If that doesn't help, I'm not sure what's going on. I use C# myself, and VB.NET has some subtle differences like the 'handles' keyword that I'm not familiar with. The only other thing I can think of is checking if the AutoEventWireup setting of the page is set to false. IIRC this is the default for VB.NET (for C# the default is true) and is the setting you need if you are using the handles keyword.
0
 
r_ShealyAuthor Commented:
I tried that but still didn't work. I checked the AutoEvent Wireup but everything looked correct.  
Id did find something else out.  Again stepping through the code; when it gets to this:

 SqlDataSource16.Select(DataSourceSelectArguments.Empty)

it WILL execute any code in the SELECTING event. But still wont execute any code in the SELECTED event.The order, from my knowledge, is SELECT goes to SELECTING then goes to SELECTED events.  Just can't get that last one.  

Is there perhaps any code I can put in the selecting event that will cause it to execute the selected event?
0
 
Seven priceFull StackCommented:
Try

If page.ispostback then
SqlDataSource16.Select(DataSourceSelectArguments.Empty)
End if

on the page load
0
 
r_ShealyAuthor Commented:
ok, I believe I found a solution.  in the aspx code I put
OnSelected="sqlDataSource16_Selected" and thank goodness but it worked.  Even though in my past experience I  never need to use that but whatever, it works now!!

0
 
pschramaCommented:
That's odd, I thought that wasn't necessary in VB.NET due to the "handles" approach, or I would have suggested that before (since I always need to do that in C#). Strange, but well done!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 7
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now