Number of records in SqlDataSource

Hi
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

simshpAsked:
Who is Participating?
 
simshpConnect With a Mentor Author 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
0
 
guru_samiConnect With a Mentor Commented:
try using DDL DataBound event...check if DDL.Items.Count>0 make it visible or else invisible.
0
 
Alfred A.Commented:
Hi,

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

0
 
Alfred A.Commented:
Hi,

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

0
All Courses

From novice to tech pro — start learning today.