2

I have a GridView, which has a column as shown below:

<asp:TemplateField HeaderText="Vendor Path" SortExpression="DocumentTemplateFieldID" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
    <ItemTemplate>
        <asp:Label ID="vendor" Height="10px" Width="60px" runat="server" Text='<%# Eval("DocumentTemplateFieldID") %>'> </asp:Label>
    </ItemTemplate>
</asp:TemplateField>

I allow sorting; however, it sorts it as if it were a string. In the database, it is an integer column.

How do I make my GridView accept that I'm really putting integers in there? I tried to convert it and that didn't work.

Code added:

Protected Sub TaskGridView_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs) Handles GridView1.Sorting
    dsData = Session("dataTableView")
    Dim sortExpression As String = e.SortExpression
    Dim direction As String = String.Empty
    If SortDirection = SortDirection.Ascending Then
        SortDirection = SortDirection.Descending
        direction = " DESC"
    Else
        SortDirection = SortDirection.Ascending
        direction = " ASC"
    End If
    Dim table As DataTable = dsData
    table.DefaultView.Sort = sortExpression + direction
    GridView1.DataSource = table
    GridView1.DataBind()
    Session("dataTableView") = table
End Sub
Private Property SortDirection() As SortDirection
    Get
        If Session("sortDir") = Nothing Then
            Session("sortDir") = SortDirection.Ascending
        End If

        Return CType(Session("sortDir"), SortDirection)
    End Get

    Set(ByVal value As SortDirection)
        Session("sortDir") = value
    End Set

End Property

Updated:

Public Function initialQuery(ByVal vendorID As String) As DataTable
    Dim objConn As IDbConnection = Nothing
    Dim dsData As New DataTable
    Dim objParams(0) As IDbDataParameter
    Try
        objConn = DBAccess.GetConnection
        objParams(0) = DBAccess.CreateParameter("DWSVendorID", DbType.String, vendorID, ParameterDirection.Input)
        'Need to figure out how to add the below code:
        If (Not IsNothing(vendorID) And Not vendorID = 0) Then

            '      strBlder.Append("WHERE B.DocumentProviderID = '" + vendorID.ToString + "' ")
        End If
        dsData = DBAccess.ExecuteDataTable(objConn, DataAccessHelper.Schema & "LLC.[DWSMappingToolInitialQuery]", objParams)

    Finally
        If Not objConn Is Nothing Then
            DBAccess.CloseConnection(objConn)
        End If
    End Try
    If dsData.Rows.Count > 0 Then
        Return dsData
    End If

    Return Nothing
End Function
4

0 回答 0