N
Nathan Sokalski
I have a DataList control that I want users to be able to sort the data in
by clicking 1 of 3 buttons. The function I have created to do this is as
follows:
Private Sub SortPoems(ByVal sortby As String)
Dim ratedpoems As New DataTable
Dim sqltext As String = "SELECT * FROM poemratings ORDER BY "
Select Case sortby
Case "title"
sqltext &= "title"
Case "rating"
sqltext &= "(totalpoints/timesrated),timesrated,title"
Case "timesrated"
sqltext &= "timesrated,(totalpoints/timesrated),title"
End Select
Dim dataadapterSelect As New System.Data.OleDb.OleDbDataAdapter(sqltext,
System.Configuration.ConfigurationManager.AppSettings("connectionstring"))
dataadapterSelect.Fill(ratedpoems)
Me.datRatings.DataSource = ratedpoems
Me.datRatings.DataBind()
End Sub
When the page first loads, I call
Me.SortPoems("title")
from Page_Load, which works fine, but when I try to call it a second time
using one of the buttons it does not work. However, if I call it twice in
Page_Load, it does work when I call it with the buttons. Why is this? What
is it that calling it a second time in Page_Load does that allows me to call
it with the buttons? I am using Microsoft Access as my database, and I am
using ASP.NET 2.0. Thanks.
by clicking 1 of 3 buttons. The function I have created to do this is as
follows:
Private Sub SortPoems(ByVal sortby As String)
Dim ratedpoems As New DataTable
Dim sqltext As String = "SELECT * FROM poemratings ORDER BY "
Select Case sortby
Case "title"
sqltext &= "title"
Case "rating"
sqltext &= "(totalpoints/timesrated),timesrated,title"
Case "timesrated"
sqltext &= "timesrated,(totalpoints/timesrated),title"
End Select
Dim dataadapterSelect As New System.Data.OleDb.OleDbDataAdapter(sqltext,
System.Configuration.ConfigurationManager.AppSettings("connectionstring"))
dataadapterSelect.Fill(ratedpoems)
Me.datRatings.DataSource = ratedpoems
Me.datRatings.DataBind()
End Sub
When the page first loads, I call
Me.SortPoems("title")
from Page_Load, which works fine, but when I try to call it a second time
using one of the buttons it does not work. However, if I call it twice in
Page_Load, it does work when I call it with the buttons. Why is this? What
is it that calling it a second time in Page_Load does that allows me to call
it with the buttons? I am using Microsoft Access as my database, and I am
using ASP.NET 2.0. Thanks.