开发者

How to sort a gridview once a radio button is selected

I'm trying to sort records in the gridview right after a radio button is selected. My approach is with the开发者_JAVA技巧 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜