Aqui dejo un ejemplo. Trabaja con access. Las dos soluciones funcionan pero una bien y otra mal:
http://82.158.36.197/Toptencopia1/topten.aspx trabaja con los registros filtrados del usuario
WHERE usuario='
<%Session.SessionID%>' , pero al click sobre la columna no ordena.
http://82.158.36.197/Toptencopia2/topten.aspx trabaja sin filtrar pero en cambio funciona la ordenacion al hacer click en la columna.
<asp:GridView ID="CustomersGridView" runat="server" AutoGenerateColumns="False"
DataSourceID="AccessDataSource1" Width="688px" AllowSorting="True"
onrowcreated="CustomersGridView_RowCreated" Font-Size="XX-Small" >
<AlternatingRowStyle BackColor="#E5E5E5" />
<HeaderStyle BackColor="#304E78" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField HtmlEncode="False" DataField="url" HeaderText="Url" SortExpression="url">
<ItemStyle Width="150px" CssClass="mio09" Wrap="True" Font-Names="Tahoma" Font-Size="XX-Small" />
<HeaderStyle Font-Size="XX-Small" ForeColor="White" HorizontalAlign="Center" Width="150px" BorderStyle="Inset" />
</asp:BoundField>
<asp:BoundField HtmlEncode="False" DataField="googlecom" HeaderText="GG1" SortExpression="googlecom">
<ItemStyle Width="30px" CssClass="mio09" />
<HeaderStyle Font-Size="XX-Small" ForeColor="White" HorizontalAlign="Center" Width="60px" BorderStyle="Inset" />
</asp:BoundField>
<asp:BoundField HtmlEncode="False" DataField="googlees" HeaderText="GG2" SortExpression="googlees">
<ItemStyle Width="30px" CssClass="mio09" />
<HeaderStyle Font-Size="XX-Small" ForeColor="White" HorizontalAlign="Center" Width="60px" BorderStyle="Inset" />
</asp:BoundField>
<asp:BoundField HtmlEncode="False" DataField="msncom" HeaderText="MS1" SortExpression="msncom">
<ItemStyle Width="30px" CssClass="mio09" />
<HeaderStyle Font-Size="XX-Small" ForeColor="White" HorizontalAlign="Center" Width="60px" BorderStyle="Inset" />
</asp:BoundField>
<asp:BoundField HtmlEncode="False" DataField="msnes" HeaderText="MS2" SortExpression="msnes">
<ItemStyle Width="30px" CssClass="mio09" />
<HeaderStyle Font-Size="XX-Small" ForeColor="White" HorizontalAlign="Center" Width="60px" BorderStyle="Inset" />
</asp:BoundField>
<asp:BoundField HtmlEncode="False" DataField="yahoocom" HeaderText="YH1" SortExpression="yahoocom">
<ItemStyle Width="30px" CssClass="mio09" />
<HeaderStyle Font-Size="XX-Small" ForeColor="White" HorizontalAlign="Center" Width="60px" BorderStyle="Inset" />
</asp:BoundField>
<asp:BoundField HtmlEncode="False" DataField="yahooes" HeaderText="YH2" SortExpression="yahooes">
<ItemStyle Width="30px" CssClass="mio09" />
<HeaderStyle Font-Size="XX-Small" ForeColor="White" HorizontalAlign="Center" Width="60px" BorderStyle="Inset" />
</asp:BoundField>
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="C:\Inetpub\wwwroot\WebTools\Topten\WebTopTenLog.mdb"SelectCommand = "
SELECT DISTINCT [url], [googlecom], [googlees], [msncom], [msnes], [yahoocom], [yahooes]
FROM [CalculosTopTen]
WHERE usuario='<%Session.SessionID%>'
ORDER BY [googlecom] DESC, [googlees] DESC, [msncom] DESC
">
</asp:AccessDataSource>
'http://msdn2.microsoft.com/es-es/library/system.web.ui.webcontrols.gridview.allowsorting(VS.80).aspxSub CustomersGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
' Use the RowType property to determine whether the
' row being created is the header row.
If e.Row.RowType = DataControlRowType.Header Then
' Call the GetSortColumnIndex helper method to determine
' the index of the column being sorted.Dim sortColumnIndex As Integer = GetSortColumnIndex()
'If sortColumnIndex <> -1 Then
' ' Call the AddSortImage helper method to add
' ' a sort direction image to the appropriate
' ' column header.
' AddSortImage(sortColumnIndex, e.Row)
'End If
End If
End Sub
' This is a helper method used to add a sort direction
' image to the header of the column being sorted.Sub AddSortImage(ByVal columnIndex As Integer, ByVal row As GridViewRow)
' Create the sorting image based on the sort direction.Dim sortImage As New Image()
If CustomersGridView.SortDirection = SortDirection.Ascending Then
sortImage.ImageUrl =
"~/Images/Ascending.jpg"
sortImage.AlternateText =
"Ascending Order"
Else
sortImage.ImageUrl =
"~/Images/Descending.jpg"
sortImage.AlternateText =
"Descending Order"
End If
' Add the image to the appropriate header cell.
row.Cells(columnIndex).Controls.Add(sortImage)
End Sub
' This is a helper method used to determine the index of the
' column being sorted. If no column is being sorted, -1 is returned.
Function GetSortColumnIndex() As Integer
' Iterate through the Columns collection to determine the index
' of the column being sorted.Dim field As DataControlField
For Each field In CustomersGridView.Columns
If field.SortExpression = CustomersGridView.SortExpression ThenReturn CustomersGridView.Columns.IndexOf(field)
End If
NextReturn -1
End Function
La unica diferencia que hay entre las dos soluciones es la linea: WHERE usuario='<%Session.SessionID%>' la primera lo tiene y la segunda no.
Alguno sabe por que?
Gracias