Building my grid dynamically, getting this error all of a sudden and it's testing my patience. Please help...
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Initialize Session Variables
Session("CarrierID") = CarriersDD.SelectedValue
Session("TransactionID") = itemTransDD.SelectedValue
Session("InOrOut") = "0"
If Session("pageSize") = "" Then
Session("pageSize") = "50"
End If
Me.PlaceHolder1.Controls.Clear()
PopulateGridOnPageInit()
'Dim grid As RadGrid = CType(PlaceHolder1.FindControl("RadGrid1"), RadGrid)
'Dim filter As RadFilter = CType(PlaceHolder1.FindControl("gridFilter"), RadFilter)
End Sub
Protected Sub PopulateGridOnPageInit()
If Not itemTransDD.SelectedValue = "" Then
displayResults.InnerHtml = ""
Dim ConnString As String = ConfigurationManager.ConnectionStrings(Session("connString")).ConnectionString
Dim conn As SqlConnection = New SqlConnection(ConnString)
conn.Open()
'***** Display Labels and Data above data grid *****'
Dim tblDisplayData As DataTable = New DataTable
Dim displaycmd As SqlCommand = New SqlCommand("tdw_spDisplayPendingRateDataMaster", conn)
displaycmd.Parameters.AddWithValue("TransactionID", Session("TransactionID"))
displaycmd.Parameters.AddWithValue("CarrierID", Session("CarrierID"))
displaycmd.CommandType = CommandType.StoredProcedure
Dim MySQLreader As SqlDataReader
MySQLreader = displaycmd.ExecuteReader()
Dim maxRead As Integer = MySQLreader.FieldCount - 1
MySQLreader.Read()
If MySQLreader.HasRows Then
For z As Integer = 0 To maxRead
If MySQLreader.GetName(z).ToString() = "Eff Date" Then
displayResults.InnerHtml += "<
span
style
=
'width:150px; margin-left:20px;'
><
b
>" + MySQLreader.GetName(z).ToString() + " -</
b
> " + Format(MySQLreader(z), "Short Date") + "</
span
>"
Else
displayResults.InnerHtml += "<
span
style
=
'width:150px; margin-left:20px;'
><
b
>" + MySQLreader.GetName(z).ToString() + " -</
b
> " + MySQLreader(z).ToString() + "</
span
>"
End If
'Check for InOrOut field value
If MySQLreader.GetName(z).ToString() = "In Or Out" Then
Session("InOrOut") = MySQLreader(z).ToString()
End If
Next
transItemDisplay.Visible = True
itemTransDD.Visible = True
CarriersDD.Visible = True
btnAccept.Visible = True
btnReject.Visible = True
lblExport.Visible = True
mngBtnExcel.Visible = True
mngBtnPDF.Visible = True
btnClearFilters.Visible = True
Else
displaymsg.InnerHtml = "There are currently no rates for you to review."
End If
conn.Close()
'***** End of display label data *****'
Dim RadGrid1 As RadGrid = New RadGrid
AddHandler RadGrid1.Init, AddressOf RadGrid1_Init
AddHandler RadGrid1.ItemCommand, AddressOf RadGrid1_ItemCommand
AddHandler RadGrid1.PageSizeChanged, AddressOf RadGrid1_PageSizeChanged
'AddHandler RadGrid1.ItemCreated, AddressOf RadGrid1_ItemCreated
'AddHandler RadGrid1.ItemDataBound, AddressOf RadGrid1_ItemDataBound
AddHandler RadGrid1.PageSizeChanged, AddressOf RadGrid1_PageSizeChanged
AddHandler RadGrid1.PdfExporting, AddressOf RadGrid1_PdfExporting
AddHandler RadGrid1.GridExporting, AddressOf RadGrid1_GridExporting
RadGrid1.ID = "RadGrid1"
RadGrid1.Width = Unit.Percentage(100)
RadGrid1.AllowPaging = True
RadGrid1.MasterTableView.PagerStyle.Mode = GridPagerMode.NextPrevNumericAndAdvanced
RadGrid1.MasterTableView.AllowCustomPaging = False
RadGrid1.MasterTableView.VirtualItemCount = "1000"
RadGrid1.MasterTableView.PagerStyle.Position = GridPagerPosition.TopAndBottom
RadGrid1.PageSize = 50
RadGrid1.AllowSorting = True
RadGrid1.AllowFilteringByColumn = True
RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric
RadGrid1.PagerStyle.Position = GridPagerPosition.TopAndBottom
RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None
RadGrid1.MasterTableView.CommandItemStyle.BackColor = Color.LightGray
RadGrid1.MasterTableView.CommandItemStyle.ForeColor = Color.Black
RadGrid1.MasterTableView.AllowFilteringByColumn = True
RadGrid1.ExportSettings.ExportOnlyData = True
RadGrid1.AutoGenerateColumns = False
RadGrid1.Skin = "Sitefinity"
RadGrid1.BorderStyle = BorderStyle.None
RadGrid1.MasterTableView.HeaderStyle.ForeColor = Color.White
RadGrid1.MasterTableView.EnableColumnsViewState = True
RadGrid1.MasterTableView.PageSize = Session("pageSize")
RadGrid1.MasterTableView.ExpandCollapseColumn.Visible = False
RadGrid1.MasterTableView.AllowMultiColumnSorting = True
RadGrid1.GroupingSettings.CaseSensitive = False
RadGrid1.EnableViewState = True
RadGrid1.MasterTableView.TableLayout = GridTableLayout.Auto
'***** Get and Display Grid Data *****'
conn.Open()
Dim dtPendingRates As DataTable = New DataTable
Dim cmd As SqlCommand = New SqlCommand("tdw_spDisplayPendingRateDataDetail", conn)
cmd.Parameters.AddWithValue("TransactionID", Session("TransactionID"))
cmd.Parameters.AddWithValue("CarrierID", Session("CarrierID"))
cmd.Parameters.AddWithValue("InOrOut", Session("InOrOut"))
cmd.CommandType = CommandType.StoredProcedure
Dim adapter As New SqlDataAdapter(cmd)
adapter.SelectCommand.CommandTimeout = 300
adapter.Fill(dtPendingRates)
If dtPendingRates.Columns.Count > 0 Then
Dim name(dtPendingRates.Columns.Count) As String
Dim i As Integer = 0
For Each column As DataColumn In dtPendingRates.Columns
Dim boundColumn As GridBoundColumn = New GridBoundColumn
RadGrid1.MasterTableView.Columns.Add(boundColumn)
boundColumn.DataField = column.ColumnName
boundColumn.HeaderText = column.ColumnName
'boundColumn.AndCurrentFilterFunction = GridKnownFunction.Contains
boundColumn.ShowFilterIcon = True
boundColumn.AutoPostBackOnFilter = True
If column.ColumnName = "Discount" Then
Session("HasDiscountFld") = column.ColumnName
End If
Next
Dim showHideMinFlag As Boolean = False
Dim showHideRateFlag As Boolean = False
'Compare data in Mimimum/Minimum New & Rate/RateNew
'If they are the same, hide the new column
For Each row As DataRow In dtPendingRates.Rows
If Session("HasDiscountFld") = "Discount" Then
'Do Nothing
Dim min As String = row.Item("Minimum").ToString
Dim minNew As String = row.Item("Minimum New").ToString
If min <> minNew Then
showHideMinFlag = True
End If
Else
Dim min As String = row.Item("Minimum").ToString
Dim minNew As String = row.Item("Minimum New").ToString
Dim rate As String = row.Item("Rate").ToString
Dim rateNew As String = row.Item("Rate New").ToString
If rate <> rateNew Then
showHideRateFlag = True
End If
If min <> minNew Then
showHideMinFlag = True
End If
End If
Next
If Session("HasDiscountFld") <> "Discount" Then
'*** Show or hide fields based on comparison between fields completed above.
If showHideMinFlag = True Then
RadGrid1.MasterTableView.GetColumn("Minimum New").Visible = True
Else
RadGrid1.MasterTableView.GetColumn("Minimum New").Visible = False
End If
If showHideRateFlag = True Then
RadGrid1.MasterTableView.GetColumn("Rate New").Visible = True
Else
RadGrid1.MasterTableView.GetColumn("Rate New").Visible = False
End If
End If
Session("HasDiscountFld") = ""
RadGrid1.DataSource = dtPendingRates
End If
conn.Close()
Try
Me.PlaceHolder1.Controls.Add(RadGrid1)
Catch ex As Exception
End Try
displaymsg.InnerHtml = "The following rate transactions are waiting to be approved. Please select a transaction and click "View" to view its details. <
asp:HyperLink
ID
=
'HyperLink1'
runat
=
'server'
>View all rates for this carrier.</
asp:HyperLink
>"
Else
Dim RadGrid1 As RadGrid = New RadGrid
RadGrid1.ID = "RadGrid1"
Try
'Me.PlaceHolder1.Controls.Add(RadGrid1)
Catch ex As Exception
End Try
displaymsg.InnerHtml = "<
h2
>There are currently no rates for you to review.</
h2
>"
If Not Session("userCarrierName") = "" Then
lblCompany.Text = Session("userCarrierName")
End If
End If
If Session("userRole") = "TDW Admin" Then
btnAccept.Visible = False
btnReject.Visible = False
End If
End Sub
Protected Sub CarriersDD_SelectedIndexChanged(sender As Object, e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles CarriersDD.SelectedIndexChanged
' Display Carrier Name on screen
lblCompany.Text = CarriersDD.SelectedItem.Text
Dim oldGrid As RadGrid
oldGrid = PlaceHolder1.FindControl("RadGrid1")
Try
PlaceHolder1.Controls.Remove(oldGrid)
Catch ex As Exception
End Try
Dim oldFilter As RadFilter
oldFilter = PlaceHolder1.FindControl("gridFilter")
Try
PlaceHolder1.Controls.Remove(oldFilter)
Catch ex As Exception
End Try
' Store CarrierID in a session variable to access in application
Session("CarrierID") = CarriersDD.SelectedValue
GetItemTransDD.DataBind()
End Sub
Protected Sub itemTransDD_SelectedIndexChanged(sender As Object, e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles itemTransDD.SelectedIndexChanged
' Store TransactionID in a session variable to access in application
Session("TransactionID") = itemTransDD.SelectedValue
Dim oldGrid As RadGrid
oldGrid = PlaceHolder1.FindControl("RadGrid1")
Try
PlaceHolder1.Controls.Remove(oldGrid)
Catch ex As Exception
End Try
Dim oldFilter As RadFilter
oldFilter = PlaceHolder1.FindControl("gridFilter")
Try
PlaceHolder1.Controls.Remove(oldFilter)
Catch ex As Exception
End Try
PopulateGridOnPageInit()
End Sub
Protected Sub CarriersDD_DataBound(sender As Object, e As EventArgs) Handles CarriersDD.DataBound
Dim combo As RadComboBox = CarriersDD
Try
CarriersDD.Items(0).Selected = True
lblCompany.Text = CarriersDD.SelectedItem.Text
' Store CarrierID in a session variable to access in application
Session("CarrierID") = CarriersDD.SelectedValue
GetItemTransDD.DataBind()
Catch ex As Exception
End Try
If Session("CarrierID") = "" Then
CarriersDD.Visible = False
Else
CarriersDD.Visible = True
End If
End Sub
Protected Sub itemTransDD_DataBound(sender As Object, e As EventArgs) Handles itemTransDD.DataBound
' Store TransactionID in a session variable to access in application
Session("TransactionID") = itemTransDD.SelectedValue
Dim oldGrid As RadGrid
oldGrid = PlaceHolder1.FindControl("RadGrid1")
Try
PlaceHolder1.Controls.Remove(oldGrid)
Catch ex As Exception
End Try
Dim oldFilter As RadFilter
oldFilter = PlaceHolder1.FindControl("gridFilter")
Try
PlaceHolder1.Controls.Remove(oldFilter)
Catch ex As Exception
End Try
If Session("TransactionID") = "" Then
itemTransDD.Visible = False
transItemDisplay.Visible = False
Else
itemTransDD.Visible = True
transItemDisplay.Visible = True
End If
PopulateGridOnPageInit()
End Sub
Private Sub RadGrid1_Init(ByVal sender As Object, ByVal e As System.EventArgs)
Dim grid As RadGrid = Me.PlaceHolder1.FindControl("RadGrid1")
Dim menu As GridFilterMenu = grid.FilterMenu
Dim i As Integer = 0
While i <
menu.Items.Count
If menu.Items(i)
.Text
=
"DoesNotContain"
Then
menu.Items(i)
.Text
=
"Does Not Contain"
i
= i + 1
ElseIf menu.Items(i)
.Text
=
"StartsWith"
Then
menu.Items(i)
.Text
=
"Starts With"
i
= i + 1
ElseIf menu.Items(i)
.Text
=
"EndsWith"
Then
menu.Items(i)
.Text
=
"Ends With"
i
= i + 1
ElseIf menu.Items(i)
.Text
=
"EqualTo"
Then
menu.Items(i)
.Text
=
"Equal To"
i
= i + 1
ElseIf menu.Items(i)
.Text
=
"NotEqualTo"
Then
menu.Items(i)
.Text
=
"Not Equal To"
i
= i + 1
ElseIf menu.Items(i)
.Text
=
"GreaterThan"
Then
menu.Items(i)
.Text
=
"GreaterThan"
i
= i + 1
ElseIf menu.Items(i)
.Text
=
"LessThan"
Then
menu.Items(i)
.Text
=
"Less Than"
i
= i + 1
ElseIf menu.Items(i)
.Text
=
"GreaterThanOrEqualTo"
Then
menu.Items(i)
.Text
=
"Greater Than Or Equal To"
i
= i + 1
ElseIf menu.Items(i)
.Text
=
"LessThanOrEqualTo"
Then
menu.Items(i)
.Text
=
"Less Than Or Equal To"
i
= i + 1
ElseIf menu.Items(i)
.Text
=
"NotBetween"
Then
menu.Items(i)
.Text
=
"Not Between"
i
= i + 1
ElseIf menu.Items(i)
.Text
=
"IsEmpty"
Then
menu.Items(i)
.Text
=
"Is Empty"
i
= i + 1
ElseIf menu.Items(i)
.Text
=
"NotIsEmpty"
Then
menu.Items(i)
.Text
=
"Is Not Empty"
i
= i + 1
ElseIf menu.Items(i)
.Text
=
"IsNull"
Then
menu.Items(i)
.Text
=
"Is Null"
i
= i + 1
ElseIf menu.Items(i)
.Text
=
"NotIsNull"
Then
menu.Items(i)
.Text
=
"Is Not Null"
i
= i + 1
Else
i
= i + 1
'menu.Items.RemoveAt(i)
End If
End While
End Sub
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs)
Dim grid As
RadGrid
=
Me
.PlaceHolder1.FindControl("RadGrid1")
If
e.CommandName
=
RadGrid
.FilterCommandName Then
Dim filterPair As
Pair
=
CType
(e.CommandArgument, Pair)
Dim colName As
String
=
filterPair
.Second.ToString()
grid.MasterTableView.GetColumn(colName)
.HeaderStyle.BackColor
= Color.DarkSlateGray
End If
End Sub
Public Sub btnExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim url As
String
=
"export_pendingrates.aspx"
ClientScript.RegisterStartupScript(Me.GetType(), "OpenWin", "<script>openNewWin('" & url & "')</
script
>")
End Sub
Protected Sub btnPDF_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim url As String = "exportPDF_pendingrates.aspx"
ClientScript.RegisterStartupScript(Me.GetType(), "OpenWin", "<
script
>openNewWin('" & url & "')</
script
>")
End Sub
Protected Sub RadGrid1_PdfExporting(ByVal sender As Object, e As GridPdfExportingArgs)
e.RawHTML = "<
div
><
img
src
=
'../../Images/tdwlogo-sm.png'
/></
div
><
div
style
=
'text-align:center; color: #000; font-weight: bold;'
>TDW Web Portal - Pending Rates</
div
><
hr
/>" + e.RawHTML + "<
div
style
=
'text-align:center'
><
hr
/>Exported on " + Date.Today + "</
div
>"
End Sub
Protected Sub RadGrid1_GridExporting(ByVal sender As Object, e As GridExportingArgs)
If e.ExportType = ExportType.Excel Then
'Set colspan on customText to 8 to account for fields being exported from Grid
Dim customText As String = "<
table
><
tr
style
=
'background-color:#D0D0D0; text-align:center; font-weight:bold;'
><
td
colspan
=
'8'
>TDW Web Portal - Active Rates - Exported on " + Date.Today + "</
td
></
tr
></
table
>"
e.ExportOutput = e.ExportOutput.Replace("<
body
>", "<
body
>" + customText)
End If
End Sub
Protected Sub btnAccept_Click(sender As Object, e As EventArgs) Handles btnAccept.Click
'Approve/Accept Rates for Carrier
Dim ConnString As String = ConfigurationManager.ConnectionStrings(Session("connString")).ConnectionString
Dim conn As SqlConnection = New SqlConnection(ConnString)
conn.Open()
Dim cmd As SqlCommand = New SqlCommand("tdw_spApprovePendingRate", conn)
cmd.Parameters.AddWithValue("TransactionID", Session("TransactionID"))
cmd.Parameters.AddWithValue("CarrierID", Session("CarrierID"))
cmd.Parameters.AddWithValue("Username", My.User.Name)
cmd.CommandType = CommandType.StoredProcedure
Dim dr As SqlDataReader
dr = cmd.ExecuteReader
If dr.RecordsAffected Then
Response.Redirect("pendingratechanges.aspx")
End If
conn.Close()
'RadWindowManager1.RadAlert("Postback from asp button on " + DateTime.Now.ToString(), 300, 110, "Action Result", Nothing)
End Sub
<
WebMethod
()> _
Public Shared Function RejectRates(ByVal comments As String) As Boolean
'Javascript calls this Function after user has entered comments for rejecting rates
'Exec's SP to reject selected rates
Dim ConnString As String = ConfigurationManager.ConnectionStrings(HttpContext.Current.Session("connString")).ConnectionString
Dim conn As SqlConnection = New SqlConnection(ConnString)
conn.Open()
Dim cmd As SqlCommand = New SqlCommand("tdw_spRejectPendingRate", conn)
cmd.Parameters.AddWithValue("TransactionID", HttpContext.Current.Session("TransactionID"))
cmd.Parameters.AddWithValue("CarrierID", HttpContext.Current.Session("CarrierID"))
cmd.Parameters.AddWithValue("Username", My.User.Name)
cmd.Parameters.AddWithValue("RejectReason", comments)
cmd.CommandType = CommandType.StoredProcedure
Dim dr As SqlDataReader
dr = cmd.ExecuteReader
If dr.RecordsAffected Then
conn.Close()
Return True
Else
conn.Close()
Return False
End If
End Function
Protected Sub RadGrid1_PageSizeChanged(ByVal sender As Object, ByVal e As GridPageSizeChangedEventArgs)
Session("pageSize") = e.NewPageSize.ToString
'sender.CurrentPageIndex = e.NewPageSize
End Sub
Protected Sub btnClearFilters_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles btnClearFilters.Click
Dim grid As RadGrid = Me.PlaceHolder1.FindControl("RadGrid1")
For Each column As GridColumn In grid.MasterTableView.Columns
column.CurrentFilterFunction = GridKnownFunction.NoFilter
column.CurrentFilterValue = String.Empty
column.HeaderStyle.BackColor = Color.FromArgb(26, 176, 157)
Next
grid.MasterTableView.FilterExpression = String.Empty
grid.MasterTableView.Rebind()
End Sub