Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

Checking row count from ObjectDataSource with Filtering

I have a lot of asp Labels acting as section headers on my page which I need to hide if there are no records in the ObjectDataSource.

This has been working fine with the code below but now that I have implemented filtering the code is still counting rows even though there aren't actually any displayed.

Can you suggest a way to take into consideration the filtering when counting the rows?
protected void ShowHidePanels()
    {
        System.Collections.IEnumerable ie = GridViewDS.Select();
        int Count = ((System.Data.DataView)(ie)).Table.Rows.Count;
        if (Count > 0)
        {
            IncomingReturnsHeaderPanel.Visible = true;
            IncomingReturnsWrap.Visible = true;
            ShowDetailsMessage.Text = "<br>Select a Return to View Details";
        }
        else
        {
            ShowDetailsMessage.Visible = true;
            ReturnDetailsView.Visible = false;
            CustomerDetailsView.Visible = false;
            FaultDetailsView.Visible = false;
            ReturnDetailsHeaderPanel.Visible = false;
            FaultDetailsHeaderPanel.Visible = false;
            CustomerDetailsHeaderPanel.Visible = false;
            ReturnDetailsWrap.Visible = false;
            FaultDetailsWrap.Visible = false;
            CustomerDetailsWrap.Visible = false;
            IncomingReturnsHeaderPanel.Visible = false;
            ShowDetailsMessage.Text = "<br>There are no incoming returns at present.";
 
///Im setting the Filtering like this...
GridViewDS.FilterExpression = "DOR >= '" + DateFromTextBox.Text + "' and DOR <= '" + DateToTextBox.Text + "'";
 
/// I then call the method above once the filterexpression has been added to try to hide all the labels if there are now no records after filtering.

Open in new window

0
andrewmilner
Asked:
andrewmilner
1 Solution
 
jabcocoCommented:
Try this

Ref:
http://forums.asp.net/p/941697/1127449.aspx
http://forums.asp.net/t/940679.aspx (using compute with count)

((System.Data.DataView)(ie)).Count;
//instead of
((System.Data.DataView)(ie)).Table.Rows.Count;

Open in new window

0
 
andrewmilnerAuthor Commented:
BINGO!.  Thank you very much!.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now