views:

161

answers:

2

Hi-- I have a asp.net page that has several SqlDataSources defined that feed data into some graphs. The problem is that the graph product does not handle "no data" very well, and throws an error. I'd like this to handle the situation more gracefully-- so I need to check whether the SqlDataSource returned data or now before rendering the graph (and if not, just post a message saying "No Data" or something).

Is there an easy way to check if the data source returned data, and do this if/then without a bunch of code behind?

Thanks!

+1  A: 

try this http://www.devcurry.com/2009/02/how-do-you-check-if-sqldatasource.html

i hope if it helps you ..

Amr Elnashar
thanks for the link AmRosh-- I don't really understand how I would use that however. Could you explain a bit more? Thank you
julio
+1  A: 

The following is taken from devcurry, which is pretty much what you are looking for.

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName],
    [ContactTitle], [Address] FROM [Customers]"
    onselected="SqlDataSource1_Selected">
</asp:SqlDataSource>

And in code behind:

Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs)

    If e.AffectedRows < 1 Then

        ' perform action

    End If

End Sub
Jack Marchetti
thanks JackM-- is it possible to do the if statement in the page, not in the code behind?
julio
Why can't you do this in the code behind?
Jack Marchetti
no reason, did it that way after all. Thanks!
julio
Keep in mind that AffectedRows also is 0 when no table is returned at all vs. just a table with zero rows.
Marc