multi-filtering and sorting a gridview

Discussion in 'ASP .Net Building Controls' started by Plateriot, Dec 15, 2008.

  1. Plateriot

    Plateriot Guest

    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("cmbTargPCP"), 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 -- ??
    Plateriot, Dec 15, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan Searle
    Replies:
    2
    Views:
    8,932
    Alan Searle
    Nov 20, 2005
  2. Sjaakie
    Replies:
    10
    Views:
    736
    Nick Gilbert
    Sep 21, 2006
  3. Harry Haller
    Replies:
    3
    Views:
    1,183
    RobinS
    Feb 1, 2007
  4. snafu7x7

    sorting and filtering oh my!

    snafu7x7, Oct 2, 2007, in forum: XML
    Replies:
    5
    Views:
    535
    Pavel Lepin
    Oct 3, 2007
  5. Michelle
    Replies:
    1
    Views:
    228
    Elton Wang
    Apr 8, 2005
Loading...

Share This Page