hi folks,
I am getting the below error msg and I tried to fix it myself and so far to no avail. can someone take a look at it and point me where i made the mistake. thank you
The GridView 'gvFederal' fired event Sorting which wasn't handled.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The GridView 'gvFederal' fired event Sorting which wasn't handled.
Source Error:
Line 93: gvFederal.DataSource = myDataSet
Line 94: gvFederal.DataBind()
Line 95: gvFederal.Sort(gvFederal.Columns(0).SortExpression, SortDirection.Ascending)
Line 96:
Line 97: End Sub
Imports System.Configuration.ConfigurationManager
Imports System.Web.UI.WebControls
Partial Class lettingReport_federalPr
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
FedProjYear()
OperatorSelector()
End If
End Sub
Sub FedProjYear()
Dim FedPrYear As ArrayList
FedPrYear = New ArrayList
FedPrYear.Add("1999")
FedPrYear.Add("2000")
FedPrYear.Add("2001")
FedPrYear.Add("2002")
FedPrYear.Add("2003")
FedPrYear.Add("2004")
FedPrYear.Add("2005")
FedPrYear.Add("2006")
FedPrYear.Add("2007")
FedPrYear.Insert(0, "--Select year--")
drYear.DataSource = FedPrYear
drYear.DataBind()
End Sub
Sub OperatorSelector()
Dim opSelector As ArrayList
opSelector = New ArrayList
opSelector.Add("<")
opSelector.Add("<=")
opSelector.Add("=")
opSelector.Add(">")
opSelector.Add(">=")
opSelector.Insert(0, "--Select Operator--")
drOperator.DataSource = opSelector
drOperator.DataBind()
End Sub
Function GetConnectionString() As String
Return ConfigurationManager.ConnectionStrings("costEstimating").ConnectionString
End Function
Protected Sub btnFederalProject_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFederalProject.Click
bindData()
End Sub
Sub bindData()
gvFederal.Visible = True
'Dim dtrFederal As OracleDataReader
Dim opSelector As String = drOperator.SelectedItem.ToString
Dim LetYr As String = drYear.SelectedItem.ToString
'Dim oOracleConn As OracleConnection
Dim connectionString As String = ConnectionStrings("costEstimating").ConnectionString
Dim oOracleConn As OracleConnection = New OracleConnection(connectionString)
oOracleConn.Open()
Dim strStringBuilder As StringBuilder
strStringBuilder = New StringBuilder
strStringBuilder.Append("SELECT DISTINCT p.pjprjnum ""Project Number"", TO_CHAR (l.contamt, '$99,999,999.99') AS ""Dollar Value"",P.PJDISTR ""District"",")
strStringBuilder.Append(" cdescr ""Job Description"", (clocat1 ||' '|| clocat2) ""Location"" ")
strStringBuilder.Append(" FROM project p, letprop l, propproj j, bidlet b, proposal r ")
strStringBuilder.Append(" WHERE(j.pcn = p.pcn) AND l.lcontid = r.contid")
strStringBuilder.Append(" AND j.contid = l.lcontid AND b.letting = l.letting")
strStringBuilder.Append(" AND NOT (REPLACE (pjprjnum, ' ', '')) LIKE '%/STATEFUNDS'")
strStringBuilder.Append(" AND l.letstat = 'A'")
strStringBuilder.Append(" AND TO_CHAR (datelet, 'YYYY') = " & LetYr)
strStringBuilder.Append(" AND l.contamt " & opSelector & ":Amount")
Dim cmdFederal As OracleCommand = New OracleCommand()
cmdFederal.Parameters.AddWithValue(":Amount", Trim(txtAmount.Text))
cmdFederal.Connection = oOracleConn
cmdFederal.CommandText = strStringBuilder.ToString
cmdFederal.CommandType = CommandType.Text
Dim adpFederal As New OracleDataAdapter(cmdFederal)
Dim myDataSet As New DataSet
adpFederal.Fill(myDataSet)
gvFederal.DataSource = myDataSet
gvFederal.DataBind()
gvFederal.Sort(gvFederal.Columns(0).SortExpression, SortDirection.Ascending)
End Sub
Protected Sub gvFederal_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvFederal.PageIndexChanging
gvFederal.PageIndex = e.NewPageIndex
bindData()
End Sub
Protected Sub gvFederal_RowCreated(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
Dim index As Integer
Dim col As DataControlField = Nothing
Dim image As HtmlImage = Nothing
If (e.Row.RowType = DataControlRowType.Header) Then
'loop through the columns in the gridview updating the header to
'mark which column is the sort column and the sort order
For index = 0 To gvFederal.Columns.Count - 1
col = gvFederal.Columns(index)
'check to see if this is the sort column
If (col.SortExpression.Equals(gvFederal.SortExpression)) Then
'this is the sort column so determine whether the ascending or
'descending image needs to be included
image = New HtmlImage()
image.Border = 0
If (gvFederal.SortDirection = SortDirection.Ascending) Then
image.Src = "images/sort_ascending.gif"
Else
image.Src = "images/sort_descending.gif"
End If
'add the image to the column header
e.Row.Cells(index).Controls.Add(image)
End If 'If (col.SortExpression = sortExpression)
Next index
End If 'If (gvBooks.SortExpression.Equals(String.Empty))
End Sub 'gvBooks_RowCreated
Protected Sub ckPage_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckPage.CheckedChanged
If ckPage.Checked = True Then
gvFederal.PageSize = 1000000
Else
gvFederal.PageSize = 15
End If
End Sub
End Class
html code
------------
<table style="width: 100%">
<tr>
<td >
</td>
</tr>
<tr>
<td >
<asp:GridView ID="gvFederal" Runat="server" SkinId="gridviewSkin" AllowSorting="true" ShowHeader="true" AutoGenerateColumns="False" OnRowCreated="gvFederal_RowCreated" >
<Columns>
<asp:BoundField DataField="Project Number" HeaderText="Project Number " SortExpression="Project Number" >
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="District" HeaderText="District " SortExpression="District" >
</asp:BoundField>
<asp:BoundField DataField="Dollar Value" HeaderText="Low Bid " SortExpression="Dollar Value" >
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Location" HeaderText="Location " SortExpression="Location" >
</asp:BoundField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
I am getting the below error msg and I tried to fix it myself and so far to no avail. can someone take a look at it and point me where i made the mistake. thank you
The GridView 'gvFederal' fired event Sorting which wasn't handled.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The GridView 'gvFederal' fired event Sorting which wasn't handled.
Source Error:
Line 93: gvFederal.DataSource = myDataSet
Line 94: gvFederal.DataBind()
Line 95: gvFederal.Sort(gvFederal.Columns(0).SortExpression, SortDirection.Ascending)
Line 96:
Line 97: End Sub
Imports System.Configuration.ConfigurationManager
Imports System.Web.UI.WebControls
Partial Class lettingReport_federalPr
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
FedProjYear()
OperatorSelector()
End If
End Sub
Sub FedProjYear()
Dim FedPrYear As ArrayList
FedPrYear = New ArrayList
FedPrYear.Add("1999")
FedPrYear.Add("2000")
FedPrYear.Add("2001")
FedPrYear.Add("2002")
FedPrYear.Add("2003")
FedPrYear.Add("2004")
FedPrYear.Add("2005")
FedPrYear.Add("2006")
FedPrYear.Add("2007")
FedPrYear.Insert(0, "--Select year--")
drYear.DataSource = FedPrYear
drYear.DataBind()
End Sub
Sub OperatorSelector()
Dim opSelector As ArrayList
opSelector = New ArrayList
opSelector.Add("<")
opSelector.Add("<=")
opSelector.Add("=")
opSelector.Add(">")
opSelector.Add(">=")
opSelector.Insert(0, "--Select Operator--")
drOperator.DataSource = opSelector
drOperator.DataBind()
End Sub
Function GetConnectionString() As String
Return ConfigurationManager.ConnectionStrings("costEstimating").ConnectionString
End Function
Protected Sub btnFederalProject_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFederalProject.Click
bindData()
End Sub
Sub bindData()
gvFederal.Visible = True
'Dim dtrFederal As OracleDataReader
Dim opSelector As String = drOperator.SelectedItem.ToString
Dim LetYr As String = drYear.SelectedItem.ToString
'Dim oOracleConn As OracleConnection
Dim connectionString As String = ConnectionStrings("costEstimating").ConnectionString
Dim oOracleConn As OracleConnection = New OracleConnection(connectionString)
oOracleConn.Open()
Dim strStringBuilder As StringBuilder
strStringBuilder = New StringBuilder
strStringBuilder.Append("SELECT DISTINCT p.pjprjnum ""Project Number"", TO_CHAR (l.contamt, '$99,999,999.99') AS ""Dollar Value"",P.PJDISTR ""District"",")
strStringBuilder.Append(" cdescr ""Job Description"", (clocat1 ||' '|| clocat2) ""Location"" ")
strStringBuilder.Append(" FROM project p, letprop l, propproj j, bidlet b, proposal r ")
strStringBuilder.Append(" WHERE(j.pcn = p.pcn) AND l.lcontid = r.contid")
strStringBuilder.Append(" AND j.contid = l.lcontid AND b.letting = l.letting")
strStringBuilder.Append(" AND NOT (REPLACE (pjprjnum, ' ', '')) LIKE '%/STATEFUNDS'")
strStringBuilder.Append(" AND l.letstat = 'A'")
strStringBuilder.Append(" AND TO_CHAR (datelet, 'YYYY') = " & LetYr)
strStringBuilder.Append(" AND l.contamt " & opSelector & ":Amount")
Dim cmdFederal As OracleCommand = New OracleCommand()
cmdFederal.Parameters.AddWithValue(":Amount", Trim(txtAmount.Text))
cmdFederal.Connection = oOracleConn
cmdFederal.CommandText = strStringBuilder.ToString
cmdFederal.CommandType = CommandType.Text
Dim adpFederal As New OracleDataAdapter(cmdFederal)
Dim myDataSet As New DataSet
adpFederal.Fill(myDataSet)
gvFederal.DataSource = myDataSet
gvFederal.DataBind()
gvFederal.Sort(gvFederal.Columns(0).SortExpression, SortDirection.Ascending)
End Sub
Protected Sub gvFederal_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvFederal.PageIndexChanging
gvFederal.PageIndex = e.NewPageIndex
bindData()
End Sub
Protected Sub gvFederal_RowCreated(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
Dim index As Integer
Dim col As DataControlField = Nothing
Dim image As HtmlImage = Nothing
If (e.Row.RowType = DataControlRowType.Header) Then
'loop through the columns in the gridview updating the header to
'mark which column is the sort column and the sort order
For index = 0 To gvFederal.Columns.Count - 1
col = gvFederal.Columns(index)
'check to see if this is the sort column
If (col.SortExpression.Equals(gvFederal.SortExpression)) Then
'this is the sort column so determine whether the ascending or
'descending image needs to be included
image = New HtmlImage()
image.Border = 0
If (gvFederal.SortDirection = SortDirection.Ascending) Then
image.Src = "images/sort_ascending.gif"
Else
image.Src = "images/sort_descending.gif"
End If
'add the image to the column header
e.Row.Cells(index).Controls.Add(image)
End If 'If (col.SortExpression = sortExpression)
Next index
End If 'If (gvBooks.SortExpression.Equals(String.Empty))
End Sub 'gvBooks_RowCreated
Protected Sub ckPage_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckPage.CheckedChanged
If ckPage.Checked = True Then
gvFederal.PageSize = 1000000
Else
gvFederal.PageSize = 15
End If
End Sub
End Class
html code
------------
<table style="width: 100%">
<tr>
<td >
</td>
</tr>
<tr>
<td >
<asp:GridView ID="gvFederal" Runat="server" SkinId="gridviewSkin" AllowSorting="true" ShowHeader="true" AutoGenerateColumns="False" OnRowCreated="gvFederal_RowCreated" >
<Columns>
<asp:BoundField DataField="Project Number" HeaderText="Project Number " SortExpression="Project Number" >
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="District" HeaderText="District " SortExpression="District" >
</asp:BoundField>
<asp:BoundField DataField="Dollar Value" HeaderText="Low Bid " SortExpression="Dollar Value" >
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Location" HeaderText="Location " SortExpression="Location" >
</asp:BoundField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>