Gridview AllowSorting causing a problem

Discussion in 'ASP .Net' started by Julia B, Nov 3, 2009.

  1. Julia B

    Julia B Guest

    Hi all, I've got a gridview bound to an ObjectDataSource which connects to a
    utility class that runs some SQL to return a dataset. This all works fine and
    the gridview has the AllowSorting property set to true. This also works fine
    but causes a knock-on problem.

    Two of the columns in the gridview are button fields which fire the grid
    RowCommand to open a file on a shared folder based on some data in one of the
    row fields, which stores the filename.

    These open the correct files when the gridview is opened, but if the user
    sorts the gridview, then when the button field is clicked the wrong file is
    opened. It seems that the sorting is visual only, i.e. if there are 3 rows
    numbered 1, 2 and 3 unsorted and the user clicks the button field for row 3,
    then the correct file for row 3 is opened. However if the user sorts the data
    so that it is in reverse order (3,2,1) and clicks row number 1 which is now
    3rd in the list, then the file for row number 3 opens.

    Does this make sense? The code for the row command is below:

    Dim index As Integer
    Dim selectedRow As GridViewRow
    Dim filePath As String
    If e.CommandName = "Changes" Then
    'if the user has selected change history, then find the serial
    number
    'of the record and open its change history
    index = Convert.ToInt32(e.CommandArgument)
    selectedRow = Me.SearchGrid.Rows(index)
    Dim serialNumber As String = selectedRow.Cells(3).Text
    Response.Redirect("ChangeHistory.aspx?SN=" & serialNumber)
    ElseIf e.CommandName = "OrigRecord" Or e.CommandName = "OrigReport"
    Then
    'if the user has selected to open the original record
    'get the selected row
    index = Convert.ToInt32(e.CommandArgument)
    selectedRow = Me.SearchGrid.Rows(index)
    Response.Buffer = False
    Response.Clear()
    Response.ClearHeaders()
    'now get the record name
    If e.CommandName = "OrigRecord" Then
    filePath = selectedRow.Cells(9).Text
    filePath = Global.Global_asax.linkPath & filePath
    Response.AppendHeader("Content-Disposition",
    "attachment;filename=" & System.IO.Path.GetFileName(filePath))
    Response.ContentType = "text/csv"
    Else
    filePath = selectedRow.Cells(10).Text
    filePath = Replace(filePath, "&", "&")
    filePath = Global.Global_asax.linkPath & filePath
    Response.AppendHeader("Content-Disposition",
    "attachment;filename=" & System.IO.Path.GetFileName(filePath))
    Response.ContentType = "text/plain"
    End If
    'now we've got the full path for the file, open it
    Response.TransmitFile(filePath)
    Response.End()
    Else
    'do nothing
    End If

    Thanks in advance.
    Julia
     
    Julia B, Nov 3, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cowboy \(Gregory A. Beamer\)

    Export datagrid(with allowsorting) to Excel

    Cowboy \(Gregory A. Beamer\), Jun 25, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    525
  2. =?Utf-8?B?a2g=?=

    DataGrid.AllowSorting and CssClass

    =?Utf-8?B?a2g=?=, Aug 2, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,553
    Joe Fallon
    Aug 3, 2004
  3. Samuel Shulman

    AllowSorting dosn't work

    Samuel Shulman, Jun 13, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    3,660
    Samuel Shulman
    Jun 13, 2006
  4. tony010409020622@

    AllowSorting = True, BUT Web DataGrid Wont Sort

    tony010409020622@, Sep 29, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    188
    Scott M.
    Sep 29, 2005
  5. Dan Dorey via .NET 247

    dynamic datagrids and allowsorting

    Dan Dorey via .NET 247, Aug 4, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    117
    Dan Dorey via .NET 247
    Aug 4, 2004
Loading...

Share This Page