tags:

views:

82

answers:

1

I'm trying to sort records in the gridview right after a radio button is selected. My approach is with the dataview, but because the dataset variable doesn't survive a round trip to the server, I don't know how to make this happen. please help!

 Public Sub GetCustomers()
        db.RunProcedure("usp_customers_get_all")
        db.doSort(radList.SelectedValue)
        gvCustomers.DataSource = db.MyView
    End Sub

Protected Sub radList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles radList.SelectedIndexChanged
        If radList.SelectedValue = 0 Then
            db.doSort(0)
            gvCustomers.DataSource = db.MyView
        End If
        If radList.SelectedValue = 1 Then
            db.doSort(1)
            gvCustomers.DataSource = db.MyView
        End If
    End Sub

 Public Sub doSort(ByVal strIn As Integer)
        If strIn = 0 Then
            MyView.Sort = "lastname, firstname"
        Else
            MyView.Sort = "username"
        End If
    End Sub
    Public Sub RunProcedure(ByVal strName As String)
        Dim objConnection As New SqlConnection(mstrConnection)
        Dim mdbDataAdapter As New SqlDataAdapter(strName, objConnection)
        Try
            mdbDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
            Me.mDataset.Clear()
            mdbDataAdapter.Fill(mDataset, "tblCustomers")
            MyView.Table = mDataset.Tables("tblCustomers")
        Catch ex As Exception
            Throw New Exception("stored procedure is " & strName.ToString & " error is " & ex.Message)
        End Try
    End Sub
+1  A: 

You could store the dataset in one of the following places and then when the post back happens just load it again from there. I have done many of these on a corporate intranet.

  1. Session Variable
  2. ViewState
  3. QueryString
  4. Cache

I cant really provide more help as you didn't specify if this is done in Ajax or if you do a full postback etc. If you provide more info I would love to help you.

Eugene Niemand
or load the dataset again from the database. choose memory vs. performance
24x7Programmer