locked
dataview of sqldatasource count problem RRS feed

  • Question

  • User1864737465 posted

     

    I have a page with 1 sqldatasource, 1 gridview and some filters (dropdownlist, etc.) at the top. When a user filters the gridview using the dropdownlists, they evenutally hit the following code:

            Me.SqlDataSource1.FilterExpression = tmpFilter
            Me.SqlDataSource1.DataBind()
            Me.GridView1.DataBind()
    
            Dim dv As DataView = Me.SqlDataSource1.Select(DataSourceSelectArguments.Empty)
            Me.lblFullCount.Text = dv.Count
            dv.RowFilter = "Column1 is null"
            Me.lblFilteredCount.Text = dv.Count

    The first pass (i.e. page load) results something like: lblFullCount = 100, lblFitleredCount = 50

    The subsequent passes (i.e. when a user filters the gridview) results in something like: lblFullCount = 16, lblFilteredCount = 50

    The problem looks to be that DV is accouting for the filterexpression and showing the new counts correctly for FullCount but when it hits the dv.RowFilter, it either reverts back to the full list or doesn't recognize the RowFilter. Either way, I'm stumped as to why this would be. WOuld appreciate any input. Thanks.

    Wednesday, April 27, 2011 1:10 PM

Answers

  • User1864737465 posted

    Thanks for your feedback but I think you may have taken "reverts" back a bit too literally if you're suggesting a session, my meaning was to say it acts as though. Also, I'm not sure If i'd even feel comfortable putting a DV into a session just from a scalability standpoint, who knows how big the datasource is and how many users would be using the page at the same time, etc.

    Anyway, it turns out the "problem" was using FilterExpressions in conjuntion with dv.count. dv.RowFilter apprently filters the ORIGINAL sqldatasource, not the FilterExpression'ed version in your code-behind. So you need to define your filter fully again, as in dv.Rowfilter = SqlDataSource1.FilterExpression. (The previous sentence will throw an error. Just replace the SqlDataSource.FilterExpression with your the correct filtering clause).

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 28, 2011 1:08 PM

All replies

  • User545302270 posted

    store it in a session

    Wednesday, April 27, 2011 10:47 PM
  • User1864737465 posted

    Thanks for your feedback but I think you may have taken "reverts" back a bit too literally if you're suggesting a session, my meaning was to say it acts as though. Also, I'm not sure If i'd even feel comfortable putting a DV into a session just from a scalability standpoint, who knows how big the datasource is and how many users would be using the page at the same time, etc.

    Anyway, it turns out the "problem" was using FilterExpressions in conjuntion with dv.count. dv.RowFilter apprently filters the ORIGINAL sqldatasource, not the FilterExpression'ed version in your code-behind. So you need to define your filter fully again, as in dv.Rowfilter = SqlDataSource1.FilterExpression. (The previous sentence will throw an error. Just replace the SqlDataSource.FilterExpression with your the correct filtering clause).

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 28, 2011 1:08 PM