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