Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Gridview AllowSorting causing a problem

 
Thread Tools Search this Thread
Old 11-03-2009, 03:49 PM   #1
Default Gridview AllowSorting causing a problem


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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
server generates Delayed Write errors copying Very large Files Phil Lewis Windows 64bit 15 07-22-2008 04:28 PM
screensaver causing my Outlook Express to freeze up and lock up mistuh Computer Support 26 03-20-2006 05:48 AM
Computer rebooting: is it a registry problem? Atlas Shrugged Computer Support 23 09-12-2005 01:47 AM
Ron Chiplin Allied Bakeries Cardiff. Project ronald.chiplin Computer Support 11 06-10-2004 02:12 AM
Freezing Problem - Memory Vincent Wonnacott Computer Support 1 05-19-2004 05:35 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46