L
Lisa
I have a web app that gets a recordset from the database and fills a
grid. You can drilldown from this table to a detail table.
Because the tables sometimes get huge, and because I have to go back
to the database again every time I postback anyway, I wanted to
disable ViewState in the grids. Just to minimize the amount of stuff
that gets downloaded to the client.
The problem is that none of the postbacks work. They postback, but
when it gets to the end of Page_Load, it just stops and never fires
the event. Both datagrids (the summary and detail) contain
OnSortCommand="DoSort". Sorting is enabled. But the SortCommand
events don't work on either table, and the ItemCommand event doesn't
work on the summary table.
Am I doing something wrong?
Here's the code:
Dim con As OleDbConnection
Private strReportTitle As String = "Player Comping"
Protected SortExpression As String
Protected SortOrder As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
con = New OleDbConnection(Application("DSN"))
'Put user code to initialize the page here
If Not Page.IsPostBack Then
'do nifty taskchecker thingie
If Not TFITools.IsTaskAssigned(Me, con.ConnectionString,
"Player Comping") Then
Dim TaskName As String =
TFITools.GetTaskName(con.ConnectionString, "Player Comping")
TaskName = Server.UrlEncode(TaskName)
Response.Redirect("../TaskInvalid.asp?TaskName=" &
TaskName, True)
Exit Sub
End If
'set default sort order
'ViewState("SortOrder") = "Desc"
'Set default from and to dates from bb_revenue table
SetDefaultFromToAuditDates()
End If
AddHandler dgMain.ItemCommand, AddressOf DoDetail
AddHandler dgMain.SortCommand, AddressOf DoSort
AddHandler dgDetail.SortCommand, AddressOf DoSort
End Sub
Private Sub SetDefaultFromToAuditDates()
'Dim cmd As New OleDbCommand("SELECT ISNULL(MIN(AuditDate),
'1/1/1900') 'FromDate', ISNULL(MAX(AuditDate), '1/1/1900') 'ToDate'
from bb_Revenue where Period_ID = 4", con)
'If con.State <> ConnectionState.Open Then con.Open()
'Dim rdr As OleDbDataReader = cmd.ExecuteReader()
'While rdr.Read
' db_FromDate.DefaultDate = CType(rdr("FromDate"),
Date).ToShortDateString
' db_ToDate.DefaultDate = CType(rdr("ToDate"),
Date).ToShortDateString
'End While
'rdr.Close()
'con.Close()
db_FromDate.DefaultDate = Now.ToShortDateString
db_ToDate.DefaultDate = Now.ToShortDateString
End Sub
Private Sub DoMain(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnRunReport.Click
'reset sorting
Session("SortOrder") = ""
Session("SortExpression") = ""
'set title
lblDetailHeader.Text = strReportTitle
'do it
DoReport(dgMain)
End Sub
Private Sub DoDetail(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs) Handles dgMain.ItemCommand
If (CType(e.CommandSource, LinkButton)).CommandName = "Detail"
Then
Dim Player_ID As String = e.Item.Cells(0).Text
Dim PlayerName As String =
CType(e.Item.Cells(1).Controls(0), LinkButton).Text
'reset sorting
Session("SortOrder") = ""
Session("SortExpression") = ""
'set title
lblPlayer_ID.Text = Player_ID
lblDetailHeader.Text = strReportTitle & "<br>Detail for: "
& PlayerName
'do it
DoReport(dgDetail)
End If
End Sub
Private Sub DoReport(ByVal dg As DataGrid)
'set header info
lblReportTime.Text = Now().ToString("MM/dd/yyyy, h:mm tt")
lblUserName.Text = GetUserFullName(Me, Application("DSN"))
lblReportDateRange.Text = db_FromDate.Value & " to " &
db_ToDate.Value
'set Excel Export attributes
IMG1.Attributes.Add("OnClick", "showInExcel(document.all." &
dg.ID.ToString & ", false, false);")
IMG2.Attributes.Add("OnClick", "showInExcel(document.all." &
dg.ID.ToString & ", true, false);")
IMG3.Attributes.Add("OnClick", "showInExcel(document.all." &
dg.ID.ToString & ", true, true);")
'set appearances
pnlDetailHeader.Visible = True
pnl_PreReport.Visible = False
pnl_Header.Width = Unit.Percentage(100)
pnl_Header.Visible = True
TFIPanel1.Expanded = False
'do the grid
Dim dt As DataTable
Dim dv As DataView
Dim FromDate As String = db_FromDate.Value
Dim ToDate As String = db_ToDate.Value
Dim Player_ID As String = lblPlayer_ID.Text
Dim RetVal As Int32
'do the specific stuff for this table
If dg.ID = "dgMain" Then
dt = TFITools.GetDataTable(con.ConnectionString,
"p_FRPlayerComping", New Object(2) {FromDate, ToDate, RetVal})
dgDetail.Visible = False
ElseIf dg.ID = "dgDetail" Then
dt = TFITools.GetDataTable(con.ConnectionString,
"p_FRPlayerCompingDtl", New Object(3) {FromDate, ToDate, Player_ID,
RetVal})
dgMain.Visible = False
End If
'sort if you need to
dv = dt.DefaultView
If Not Session("SortExpression") = "" Then
dv.Sort = Session("SortExpression") & " " &
ViewState("SortOrder")
End If
dg.DataSource = dv
'bind and display
dg.DataBind()
dg.Visible = True
End Sub
Public Sub DoSort(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
dgMain.SortCommand, dgDetail.SortCommand
'change sort direction if the previous column sorted is the
'same as the current column sorted
SortExpression = e.SortExpression
If SortExpression.Equals(Session("SortExpression").ToString())
Then
SortOrder =
IIf(Session("SortOrder").ToString().StartsWith("ASC"), "DESC", "ASC")
Else
SortOrder = "ASC"
End If
'set the session variables to new value
Session("SortExpression") = SortExpression
Session("SortOrder") = SortOrder
DoReport(CType(e.CommandSource, DataGrid))
End Sub
Thanks,
Lisa
grid. You can drilldown from this table to a detail table.
Because the tables sometimes get huge, and because I have to go back
to the database again every time I postback anyway, I wanted to
disable ViewState in the grids. Just to minimize the amount of stuff
that gets downloaded to the client.
The problem is that none of the postbacks work. They postback, but
when it gets to the end of Page_Load, it just stops and never fires
the event. Both datagrids (the summary and detail) contain
OnSortCommand="DoSort". Sorting is enabled. But the SortCommand
events don't work on either table, and the ItemCommand event doesn't
work on the summary table.
Am I doing something wrong?
Here's the code:
Dim con As OleDbConnection
Private strReportTitle As String = "Player Comping"
Protected SortExpression As String
Protected SortOrder As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
con = New OleDbConnection(Application("DSN"))
'Put user code to initialize the page here
If Not Page.IsPostBack Then
'do nifty taskchecker thingie
If Not TFITools.IsTaskAssigned(Me, con.ConnectionString,
"Player Comping") Then
Dim TaskName As String =
TFITools.GetTaskName(con.ConnectionString, "Player Comping")
TaskName = Server.UrlEncode(TaskName)
Response.Redirect("../TaskInvalid.asp?TaskName=" &
TaskName, True)
Exit Sub
End If
'set default sort order
'ViewState("SortOrder") = "Desc"
'Set default from and to dates from bb_revenue table
SetDefaultFromToAuditDates()
End If
AddHandler dgMain.ItemCommand, AddressOf DoDetail
AddHandler dgMain.SortCommand, AddressOf DoSort
AddHandler dgDetail.SortCommand, AddressOf DoSort
End Sub
Private Sub SetDefaultFromToAuditDates()
'Dim cmd As New OleDbCommand("SELECT ISNULL(MIN(AuditDate),
'1/1/1900') 'FromDate', ISNULL(MAX(AuditDate), '1/1/1900') 'ToDate'
from bb_Revenue where Period_ID = 4", con)
'If con.State <> ConnectionState.Open Then con.Open()
'Dim rdr As OleDbDataReader = cmd.ExecuteReader()
'While rdr.Read
' db_FromDate.DefaultDate = CType(rdr("FromDate"),
Date).ToShortDateString
' db_ToDate.DefaultDate = CType(rdr("ToDate"),
Date).ToShortDateString
'End While
'rdr.Close()
'con.Close()
db_FromDate.DefaultDate = Now.ToShortDateString
db_ToDate.DefaultDate = Now.ToShortDateString
End Sub
Private Sub DoMain(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnRunReport.Click
'reset sorting
Session("SortOrder") = ""
Session("SortExpression") = ""
'set title
lblDetailHeader.Text = strReportTitle
'do it
DoReport(dgMain)
End Sub
Private Sub DoDetail(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs) Handles dgMain.ItemCommand
If (CType(e.CommandSource, LinkButton)).CommandName = "Detail"
Then
Dim Player_ID As String = e.Item.Cells(0).Text
Dim PlayerName As String =
CType(e.Item.Cells(1).Controls(0), LinkButton).Text
'reset sorting
Session("SortOrder") = ""
Session("SortExpression") = ""
'set title
lblPlayer_ID.Text = Player_ID
lblDetailHeader.Text = strReportTitle & "<br>Detail for: "
& PlayerName
'do it
DoReport(dgDetail)
End If
End Sub
Private Sub DoReport(ByVal dg As DataGrid)
'set header info
lblReportTime.Text = Now().ToString("MM/dd/yyyy, h:mm tt")
lblUserName.Text = GetUserFullName(Me, Application("DSN"))
lblReportDateRange.Text = db_FromDate.Value & " to " &
db_ToDate.Value
'set Excel Export attributes
IMG1.Attributes.Add("OnClick", "showInExcel(document.all." &
dg.ID.ToString & ", false, false);")
IMG2.Attributes.Add("OnClick", "showInExcel(document.all." &
dg.ID.ToString & ", true, false);")
IMG3.Attributes.Add("OnClick", "showInExcel(document.all." &
dg.ID.ToString & ", true, true);")
'set appearances
pnlDetailHeader.Visible = True
pnl_PreReport.Visible = False
pnl_Header.Width = Unit.Percentage(100)
pnl_Header.Visible = True
TFIPanel1.Expanded = False
'do the grid
Dim dt As DataTable
Dim dv As DataView
Dim FromDate As String = db_FromDate.Value
Dim ToDate As String = db_ToDate.Value
Dim Player_ID As String = lblPlayer_ID.Text
Dim RetVal As Int32
'do the specific stuff for this table
If dg.ID = "dgMain" Then
dt = TFITools.GetDataTable(con.ConnectionString,
"p_FRPlayerComping", New Object(2) {FromDate, ToDate, RetVal})
dgDetail.Visible = False
ElseIf dg.ID = "dgDetail" Then
dt = TFITools.GetDataTable(con.ConnectionString,
"p_FRPlayerCompingDtl", New Object(3) {FromDate, ToDate, Player_ID,
RetVal})
dgMain.Visible = False
End If
'sort if you need to
dv = dt.DefaultView
If Not Session("SortExpression") = "" Then
dv.Sort = Session("SortExpression") & " " &
ViewState("SortOrder")
End If
dg.DataSource = dv
'bind and display
dg.DataBind()
dg.Visible = True
End Sub
Public Sub DoSort(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
dgMain.SortCommand, dgDetail.SortCommand
'change sort direction if the previous column sorted is the
'same as the current column sorted
SortExpression = e.SortExpression
If SortExpression.Equals(Session("SortExpression").ToString())
Then
SortOrder =
IIf(Session("SortOrder").ToString().StartsWith("ASC"), "DESC", "ASC")
Else
SortOrder = "ASC"
End If
'set the session variables to new value
Session("SortExpression") = SortExpression
Session("SortOrder") = SortOrder
DoReport(CType(e.CommandSource, DataGrid))
End Sub
Thanks,
Lisa