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. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.