Greetings all... I have learned a wealth of knowledge reading and searching through all the threads in this forum. However, I am at a loss to find a solution to my problem, despite reviewing all relevant posts.
I have a form that is correctly populating a datagrid when a query executes. Unfortunately, whenever I tried to re-sort or advance to another page, I get nothing but a blank page. I have a label embedded on the form that should be changing when the OnSortCommand or OnPageIndexChanged events fire. Unfortunately, the label never changes which is an indication to me that the event is not firing. The pertinent code follows:
Datagrid:
Page_Load (QryResults is the name of the datagrid):
Binding QryResults data:
Subs for sorting/paginating QryResults:
One final note. I set AutoGenerateColumns="TRUE" in another sub that configures the datagrid format. I need to autogenerate columns because the SQL commands that run from the form will generate different numbers of columns. All help is appreciated.
I have a form that is correctly populating a datagrid when a query executes. Unfortunately, whenever I tried to re-sort or advance to another page, I get nothing but a blank page. I have a label embedded on the form that should be changing when the OnSortCommand or OnPageIndexChanged events fire. Unfortunately, the label never changes which is an indication to me that the event is not firing. The pertinent code follows:
Datagrid:
Code:
<asp:datagrid id="QryResults" style="Z-INDEX: 103; LEFT: 8px; POSITION: absolute; TOP: 304px" runat="server" Font-Names="Arial Narrow" Width="888px" OnPageIndexChanged="dg_page" OnSortCommand="dg_sort" AllowSorting="True"></asp:datagrid>
Page_Load (QryResults is the name of the datagrid):
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sql As String
Dim conn As New SqlConnection()
Dim farm As String
If Not IsPostBack Then
farm = farmselect()
InitializeRptList()
strConnection = ConfigurationSettings.AppSettings(farm)
conn.ConnectionString() = strConnection
conn.Open()
PopulateApps(conn)
InitializeServers()
ConfigQryResults()
sql = "Select * from lu_appname"
QryResults.Visible = False
Bind_QryResults(sql)
lblSampleData.Text = "Nothing to report yet"
End If
Page.DataBind()
dd_ServerName.Items.Insert(0, "")
rbFarmSelect.AutoPostBack = True
'dd_AppName.Items.Remove("")
End Sub
Binding QryResults data:
Code:
Private Sub Bind_QryResults(ByVal locsql As String)
Dim conn As New SqlConnection()
Dim farm As String
farm = farmselect()
strConnection = ConfigurationSettings.AppSettings(farm)
conn.ConnectionString() = strConnection
conn.Open()
sqlCmd = New SqlCommand(locsql, conn)
da = New SqlDataAdapter(sqlCmd)
da.Fill(ds)
QryResults.DataSource = ds
QryResults.DataBind()
conn.Close()
End Sub
Subs for sorting/paginating QryResults:
Code:
Sub dg_page(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs) Handles QryResults.PageIndexChanged
Dim newsql As String
Dim s, f, g, h, o, w As String
lblSampleData.Text = "Selected Page Index: " & e.NewPageIndex
s = lbSql.Items.Item(0).Value
f = lbSql.Items.Item(1).Value
g = lbSql.Items.Item(2).Value
h = lbSql.Items.Item(3).Value
w = lbSql.Items.Item(4).Value
o = lbSql.Items.Item(5).Value
newsql = s & f & g & h & w & o
QryResults.CurrentPageIndex = e.NewPageIndex
Bind_QryResults(newsql)
End Sub
Sub dg_sort(ByVal sender As Object, ByVal e As DataGridSortCommandEventArgs) Handles QryResults.SortCommand
Dim newsql As String
Dim s, f, g, h, o, w As String
lblSampleData.Text = "Selected Sort column: " & e.SortExpression
s = lbSql.Items.Item(0).Value
f = lbSql.Items.Item(1).Value
g = lbSql.Items.Item(2).Value
h = lbSql.Items.Item(3).Value
w = lbSql.Items.Item(4).Value
o = e.SortExpression
newsql = s & f & g & h & w & o
Bind_QryResults(newsql)
End Sub
One final note. I set AutoGenerateColumns="TRUE" in another sub that configures the datagrid format. I need to autogenerate columns because the SQL commands that run from the form will generate different numbers of columns. All help is appreciated.