Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Building Controls (http://www.velocityreviews.com/forums/f59-asp-net-building-controls.html)
-   -   multi-filtering and sorting a gridview (http://www.velocityreviews.com/forums/t759040-multi-filtering-and-sorting-a-gridview.html)

Plateriot 12-15-2008 08:51 PM

multi-filtering and sorting a gridview
 
I have a gridview that I have multiple filters which I have set up in the
header template of a gridview...

This gridview already has an object data source called: "odsTargetCases"

My following example of the one combobox as a filter is working with the
exception of two things:
1) If I select the default value '*All*' AFTER successfully filtering a
gridview - the gridview comes up blank.

2) If I sort any of the other fields, the gridview also comes up blank

I use 'BindTargetGridview' to 'adjust' the object data source depending on
if any combobox has been selected.


Private Sub BindTargetGridview()

Dim condition As String = Nothing

If gvTarget.HeaderRow IsNot Nothing Then
Dim cmbPCP As DropDownList =
DirectCast(gvTarget.HeaderRow.FindControl("cmbTarg PCP"), DropDownList)
strTargetPCP = cmbPCP.SelectedValue

If cmbPCP.SelectedValue <> "*All*" Then
condition = "ProvName='" & strTargetPCP & "'"
End If
End If


If condition IsNot Nothing Then
odsTargetCases.FilterExpression = condition
End If

gvTarget.DataSourceID = ""
gvTarget.DataSourceID = "odsTargetCases"
gvTarget.DataBind()


End Sub

I also put this logic in the RowDataBound event to 'retain' the selected
value that a use selects in a variable called strTargetPCP:

Protected Sub gvTarget_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.Header Then
Dim cmbPCP As DropDownList =
DirectCast(e.Row.FindControl("cmbTargPCP"), DropDownList)

cmbPCP.SelectedValue = strTargetPCP


End If

End Sub

Finally, I put the BindTargetGridview routine in the Sorting event of the
gridview

Protected Sub gvTarget_Sorting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewSortEventArgs)
BindTargetGridview()
End Sub

I can't figure out why I don't see the sort results (comes up blank after
soring) , or why whenever I select the default value (*All*) the gridview
comes up blank -- ??




All times are GMT. The time now is 08:10 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57