GridView中的整数列正在按字符串排序

时间:2012-08-13 21:17:10

标签: asp.net vb.net gridview gridview-sorting

我有GridView,其中有一列如下所示:

<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>

我允许排序;但是,它将它分类为一个字符串。在数据库中,它是一个整数列。

如何让GridView接受我真正把整数放在那里?我试图转换它,但这不起作用。

已添加代码:

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

更新:

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

0 个答案:

没有答案