Click here to Skip to main content
15,916,378 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: working with USB Pin
Dr.Walt Fair, PE28-Jul-11 19:26
professionalDr.Walt Fair, PE28-Jul-11 19:26 
QuestionWhere to update datagrid cells Pin
RudyVB6827-Jul-11 7:26
RudyVB6827-Jul-11 7:26 
AnswerRe: Where to update datagrid cells Pin
Suresh Suthar27-Jul-11 20:40
professionalSuresh Suthar27-Jul-11 20:40 
GeneralRe: Where to update datagrid cells Pin
LCARS x3211-Aug-11 6:24
LCARS x3211-Aug-11 6:24 
QuestionGridView appears to have no data when trying to sort it Pin
dannyboi8627-Jul-11 1:12
dannyboi8627-Jul-11 1:12 
AnswerRe: GridView appears to have no data when trying to sort it Pin
Shameel27-Jul-11 2:24
professionalShameel27-Jul-11 2:24 
GeneralDataAdapter / Datatable Pin
David Mujica27-Jul-11 2:49
David Mujica27-Jul-11 2:49 
GeneralRe: DataAdapter / Datatable Pin
dannyboi8627-Jul-11 3:29
dannyboi8627-Jul-11 3:29 
GeneralRe: DataAdapter / Datatable Pin
David Mujica27-Jul-11 10:49
David Mujica27-Jul-11 10:49 
GeneralRe: DataAdapter / Datatable Pin
dannyboi8627-Jul-11 22:29
dannyboi8627-Jul-11 22:29 
GeneralRe: DataAdapter / Datatable Pin
Shameel28-Jul-11 3:16
professionalShameel28-Jul-11 3:16 
GeneralRe: DataAdapter / Datatable Pin
David Mujica28-Jul-11 3:20
David Mujica28-Jul-11 3:20 
GeneralRe: DataAdapter / Datatable Pin
dannyboi8628-Jul-11 4:59
dannyboi8628-Jul-11 4:59 
GeneralRe: DataAdapter / Datatable Pin
David Mujica28-Jul-11 9:59
David Mujica28-Jul-11 9:59 
GeneralRe: DataAdapter / Datatable Pin
dannyboi8628-Jul-11 22:34
dannyboi8628-Jul-11 22:34 
GeneralRe: DataAdapter / Datatable Pin
David Mujica29-Jul-11 3:12
David Mujica29-Jul-11 3:12 
GeneralRe: DataAdapter / Datatable Pin
dannyboi8629-Jul-11 5:58
dannyboi8629-Jul-11 5:58 
GeneralRe: DataAdapter / Datatable Pin
David Mujica1-Aug-11 10:50
David Mujica1-Aug-11 10:50 
In the section of code that loads the datatable to the grid, I had to store the datatable in a session variable.

VB
sqlAdapter.Fill(sqlDataTable)

' Here is where I'm storing the data in a session variable
If Not (Session("TaskTable") Is Nothing) Then
    Session.Remove("TaskTable")
End If

Session("TaskTable") = sqlDataTable

GridView2.DataSource = sqlDataTable


Here's the code for the "Sorting" event of the grid.

VB
    Protected Sub GridView2_Sorting(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView2.Sorting
        Dim dt As DataTable

        ' Now I'm pulling the data from the session variable out.
        dt = TryCast(Session("TaskTable"), DataTable)

        Dim dv As New DataView(dt)

' I have to store the Sort Direction in the Viewstate because the Grid 
' does not automatically remember the change of the sort direction.

        If ViewState("SortDirection") Is Nothing Then
            ViewState("SortDirection") = "ASC"
        End If

        If ViewState("SortDirection") = "ASC" Then
            dv.Sort = e.SortExpression & " " & "DESC"
            ViewState("SortDirection") = "DESC"
        Else
            dv.Sort = e.SortExpression & " " & "ASC"
            ViewState("SortDirection") = "ASC"
        End If

        GridView2.DataSource = dv
        GridView2.DataBind()
    End Sub


Hopefully this will work for you, but I don't know if I would use this type of processing for large datatables and many users. Storing the datatable in a session variable take server memory and each person would have a copy of the datatable.

You could build a more sophisticated "GetData" routine and have the stored procedure return the data sorted for you, then re-bind it to the Gridview.

Hope this works for you.
Thumbs Up | :thumbsup:
GeneralRe: GridView appears to have no data when trying to sort it Pin
dannyboi8627-Jul-11 3:45
dannyboi8627-Jul-11 3:45 
GeneralRe: GridView appears to have no data when trying to sort it Pin
Shameel27-Jul-11 5:23
professionalShameel27-Jul-11 5:23 
QuestionSearch and delete files Pin
hendrikbez26-Jul-11 22:29
hendrikbez26-Jul-11 22:29 
AnswerRe: Search and delete files Pin
Andy_L_J26-Jul-11 23:09
Andy_L_J26-Jul-11 23:09 
AnswerRe: Search and delete files Pin
Dave Kreskowiak27-Jul-11 1:27
mveDave Kreskowiak27-Jul-11 1:27 
AnswerRe: Search and delete files Pin
Carmelo La Monica27-Jul-11 2:14
professionalCarmelo La Monica27-Jul-11 2:14 
GeneralRe: Search and delete files Pin
hendrikbez27-Jul-11 19:49
hendrikbez27-Jul-11 19:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.