dwinn 0 Junior Poster in Training

I am developing a site in ASP.Net and VB.Net that will enable users to sort data in a GridView in Ascending or Descending order.

The records are coming from an SQL Server Express database.

I go to click on a column heading to sort the data and I get the following error:

'Conversion from string "Barcode" to type 'Double' is not valid.'

Please note that Barcode is one of my column headings.

Below is the code I am using for the sorting:

Property GridViewSortDirection() As SortDirection
            Get
                If IsNothing(ViewState.Item("GridViewSortDirection")) Then
                    Return SortDirection.Descending
                End If
                Return ViewState.Item("GridViewSortDirection")
            End Get
 
            Set(ByVal Value As SortDirection)
                ViewState.Item("GridViewSortDirection") = Value
            End Set
 
        End Property
   
        
        
        Function GetSortDirection() As SortDirection
  
            Dim GridViewSortDirectionNew As SortDirection
 
            Select Case GridViewSortDirection
 
                Case SortDirection.Descending
                    GridViewSortDirectionNew = SortDirection.Ascending
                    
                Case SortDirection.Ascending
                    GridViewSortDirectionNew = SortDirection.Descending
                    
                Case Else
                    GridViewSortDirectionNew = SortDirection.Descending
                    
            End Select
            GridViewSortDirection = GridViewSortDirectionNew
            
            Return GridViewSortDirectionNew
            
        End Function
        

  
        Protected Sub GridView_Sorting1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView2.Sorting
            
            If e.SortExpression = SortDirection.Ascending Then
                GridViewSortDirection = SortDirection.Descending
            Else
                GridViewSortDirection = SortDirection.Ascending
            End If

        End Sub

The error message points to the following line:

If e.SortExpression = SortDirection.Ascending Then

Does anybody have any ideas on why I am getting this and how it can be overcome?

All help and advice will be much appreciated.

Thanks,

Dan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.