Link to home
Start Free TrialLog in
Avatar of simshp
simshpFlag for Israel

asked on

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

SOLUTION
Avatar of guru_sami
guru_sami
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial