Last post Apr 28, 2011 01:08 PM by Team929
Apr 27, 2011 01:10 PM|Team929|LINK
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
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.
Apr 27, 2011 10:47 PM|wilfred.nyan|LINK
store it in a session
Apr 28, 2011 01:08 PM|Team929|LINK
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).