|
-
May 28th, 2003, 10:02 AM
#1
Thread Starter
Lively Member
Records Disappear When I Sort
I have a web form with a text box, button and a data grid. when clicked the button will populate the data grid with records that match the text box value. This part works.
The column headers are sortable so the user can put the records in whatever order they want. However when I click a header to sort by the records disappear. The code executes without error, but no records are returned. I have researched Page.IsPostBack and View States to see if that would solve the problem, but it hasn't yet.
Below is my code to populate the data grid and sort the table. I found the code for sorting in the help files. The prerender code is from ASP.Net for Dummies. They say it is good practice to store all your variables after the page loads.
Code:
Dim UserName As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IsPostBack Then
UserName = CStr(ViewState("UName"))
End If
End Sub
Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
ViewState("UName") = UserName
End Sub
Private Sub btnFillGrids_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFillGrids.Click
If fvUserName.IsValid Then
UserName = txtUserName.Text
cmdAssigned.Parameters.Item(0).Value = UserName
daAssigned.SelectCommand.Connection.Open()
daAssigned.Fill(dsAssigned)
daAssigned.SelectCommand.Connection.Close()
dgAssigned.DataBind()
cnnCWO2.Dispose()
cmdAssigned.Dispose()
cnnCWO2 = Nothing
cmdAssigned = Nothing
End If
End Sub
Private Sub dgAssigned_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgAssigned.SortCommand
dvAssigned.Sort = e.SortExpression
dgAssigned.DataBind()
End Sub
The other piece that is confusing me is I have a data grid on another page that works fine. That data grid has no parameters passed to it though.
Thank you in advance.
Jason Meckley
Database Analyst
WITF
-
May 28th, 2003, 12:34 PM
#2
Frenzied Member
In the sort command sub, make sure you fill the the DataSet again. Remember the web is stateless, so when you first fill the DataSet, you will have to fill it again if you want to use it somewhere else, or you could just put it in a session variable.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|