Number of records in SqlDataSource

I need to know the number of records returned after a I have applied a filter to a sqldatasource. I see that one should use the OnSelected event and capture the detail there. However that event is not firing for some reason. I filter a DDL based on a selection from another DDL.  The 1st piece of code set the filter - which works - and then I need to see if any rows are returned. If they are I make the 2nd DDL visible and show the records else I make the DDL invisible.
Thank you
protected void properties_SelectedIndexChanged(object sender, EventArgs e)
            PropertySubdivion.FilterExpression = "listing_id = " + properties.SelectedItem.Value.ToString();


<asp:SqlDataSource ID="PropertySubdivion" ConnectionString="<%$ ConnectionStrings:ConnString %>"
        ProviderName="<%$ ConnectionStrings:ConnString.ProviderName %>"  SelectCommand="SELECT id, listing_id, subdivision FROM para_subdivision"
        runat="server" OnSelected="PropertySubdivion_Selected"></asp:SqlDataSource>

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

try using DDL DataBound event...check if DDL.Items.Count>0 make it visible or else invisible.
Alfred A.Commented:

Try this using the AffectedRows property of the Selected event of the SqlDataSource, for example:
Protected Sub PropertySubdivion_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEvent Args) Handles PropertySubdivion.Selected

  Label1.Text = String.Format("rows count: {0}", e.AffectedRows)

End Sub

Open in new window

Alfred A.Commented:

Oops.  I didn't realise you are using C#, here is the C# equivalent of the previous code.
protected void PropertySubdivion_Selected(object sender, System.Web.UI.WebControls.SqlDataSourceStatusEvent e, void Args) {
        Label1.Text = string.Format("rows count: {0}", e.AffectedRows);

Open in new window

simshpAuthor Commented:
Hi Alfred1, I have implemented the PropertySubdivion_Selected ... the problem is that its not firing.

Hi guru_sami:, Tried this option, also does not seem to fire once I do the check. At the moment I have done a db look up for the no. of rows in the properties_SelectedIndexChanged event and made visible / invisible depending return value returned

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.