I have a simple SqlDataSource control that retrieves six category names and their Id from a Category table using the SELECT statement:
SelectCommand="SELECT [Name], [CategoryId] FROM [Categories] ORDER BY [Name]"
I have a DropDownList bound to the SqlDataSource and I see the retrieved categories fine in the drop down list, so this is working fine.
But Id like to try to look inside whats happening using the Selected event handler for the SqlDataSource.
Microsoft says that for the Selected event:
"Occurs when a data retrieval operation has completed. Handle the Selected event to examine the values of output parameters after a data retrieval operation has completed. The output parameters are available from the SqlDataSourceStatusEventAr
gs object that is associated with the event."
And they give some sample code you can put in the Selected event handler to show the command parameters:
Protected Sub categoriesDataSource_Selec
ted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.
Dim cmd As IDbCommand
cmd = e.Command
Dim param As SqlParameter
Label1.Text = "Parameter return values: "
For Each param In cmd.Parameters
' Extract the name and value of the parameter.
Label1.Text = Label1.Text & param.ParameterName & " - " & _
End Sub ' OnSelectedHandler
The first problem is that the For Each code doesnt seem to work for me. I can break at the "Label1.Text =" line and then step to the For Each, but stepping into the For Each goes directly to the End Sub line, as if there were 0 parameters. But I can see by opening up the e > command > parameters that theres a bunch of stuff there, like count (0), IsFixedSize (False). Is count=0 the problem, maybe?
The second problem is that I dont see anything in e that shows me the output parameters after the data retrieval operation. Im expecting to see the actual category names retrieved from the Cataegory table, like Cars, Boats, etc.
Does anyone know whats going on here and why Im not seeing what I expect?
Thanks for any help.