Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort first but then its not grabbing the correct information for that

Status
Not open for further replies.

ac11nyc

Programmer
Oct 1, 2003
94
US
I have a datagrid that has a hyperlink in the 1st column that once clicked, it sends them to another page with the individuals SSN being sent over to get information for that page. The only problem is that when i sort the datagrid and then i click on an individuals name, it grabs the row from the original query and not the row that was clicked after the sort command was executed.

heres my code:
Try
Dim a As String = e.CommandName
If e.CommandName = "GoToNonProducerReviewChecklist" Then
Dim ds As DataSet = GetNonProducerReviewList()
Dim r As Integer = CInt(e.Item.ItemIndex)
Session("SSN") = ds.Tables("NonProducerReviewList").Rows(r).Item("SSN")
Dim Script As New System.Text.StringBuilder
With Script
.Append("<script language='javascript'>")
.Append("var newWin = window.open('./StateChecklist.aspx','StateRegistrationRenewal','scrollbars=yes,resize=yes,height=750, width=1000');")
.Append("</script>")
End With
RegisterStartupScript("OpenNewWindow", Script.ToString())
End If
Catch ex As Exception
lblMessage.Text = ex.Message
End Try

how do i get it so that even after a sort command, it grabs the row clicked and not the row that was there at the original state of the page??

any help will be greatly appreciated. thanks AC
 
The problem with the datagrid sort function is that is not relavant to the position of the row in the grid. Instead it is relavant to the row in the datasource. On postback the grid is not repopulated from the datasource, but from memory, which means the Itemindex will always be the same as the first time that the data was loaded.

I recomend that you create a custom sorting solution that will re-get the data from the database in the Sorted order you want, then rebind that data to the grid, this way you are sure that the row the user clicks on, contains the correct record.

Look at aspnet.4guysfromrolla.com and look at there articles on the extensive use of the datagrid

Good luck


George Oakes
Check out this awsome .Net Resource!
 
Well this isnt a dataset where i can just say which column to sort by and send that to the database and it will come back corrrectly sorted. I have programatically created this dataset due to the fact that simple joins couldnt get all the information needed for the complete dataset.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top