Error trying to get totals in footer

G

Guest

I have gotten the following error in trying to get totals to come out on a
footer.

Server Error in '/test' Application.
----------------------------------------------------------------------------
----

DataBinder.Eval: 'System.Data.Common.DbDataRecord' does not contain a
property with the name ViewCount.
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: DataBinder.Eval:
'System.Data.Common.DbDataRecord' does not contain a property with the name
ViewCount.

Source Error:


Line 69: If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Line 70: 'Snip out the ViewCount
Line 71: Dim viewCount As Integer =
Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "ViewCount"))
Line 72: viewCountSum += viewCount
Line 73: ElseIf e.Item.ItemType = ListItemType.Footer Then


Source File: c:\inetpub\wwwroot\test\Sales\j2list.aspx.vb Line: 71

Stack Trace:


[HttpException (0x80004005): DataBinder.Eval:
'System.Data.Common.DbDataRecord' does not contain a property with the name
ViewCount.]
System.Web.UI.DataBinder.GetPropertyValue(Object container, String
propName)
System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts)
System.Web.UI.DataBinder.Eval(Object container, String expression)
test.j2list.mydatagrid_itemdatabound(Object sender, DataGridItemEventArgs
e) in c:\inetpub\wwwroot\test\Sales\j2list.aspx.vb:71
System.Web.UI.WebControls.DataGrid.OnItemDataBound(DataGridItemEventArgs
e)
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource)
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
test.j2list.BindGrid() in c:\inetpub\wwwroot\test\Sales\j2list.aspx.vb:59
test.j2list.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\test\Sales\j2list.aspx.vb:49
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


The code that generates the error is here:

Public Sub mydatagrid_itemdatabound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)

If (e.Item.ItemType = ListItemType.Footer) Then

Dim rows As Integer

rows = DataGrid1.Items.Count

e.Item.Cells(6).Text = "Total Purchase Orders: (" & rows & ")"

End If

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then

'Snip out the ViewCount

Dim viewCount As Integer = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem,
"ViewCount"))

viewCountSum += viewCount

ElseIf e.Item.ItemType = ListItemType.Footer Then

'e.Item.Cells(11).Text = "Total: " & String.Format("{0:#,###}",
viewCountSum)

e.Item.Cells(11).Text = viewCountSum

End If

End Sub



If I comment out the Viewcount in the second part of the Sub, it works fine,
putting out a count in the footer of the number of rows in the datagrid.

Stepping through the code, it will go thru the if statements once on the
header, and then it'll blow up on the footer. I want to put a count of the
rows in column 6, and then put totals of columns 11, 12 & 13 in the footer.



Any ideas as to what's happening?



SC
 
C

Cowboy \(Gregory A. Beamer\) [MVP]

You are asking the DataBinder to evaluate the DataTable for a property
called viewCount, which is a value you have created. If you wish to bind,
you have two options.

1. Set up a label in the footer and set the value from CodeBehind. Something
like:

MyFooterLabel.Text = viewCount.ToString()

2. Use simple binding
a. Set up viewCount as a page scoped variable

Protected viewCount As Integer = 0

In you code, you continue to set as you have. Then, you bind like so (may
have to dink with syntax - I prefer the push method (#1) instead of the pull
below):

<%# =viewCount %>

If you are using DataViews, tables, et al, you have other ways of reaching
counts. With a DataReader, you can geta count after full read.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
I have gotten the following error in trying to get totals to come out on a
footer.

Server Error in '/test' Application.
-------------------------------------------------------------------------- --
----

DataBinder.Eval: 'System.Data.Common.DbDataRecord' does not contain a
property with the name ViewCount.
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: DataBinder.Eval:
'System.Data.Common.DbDataRecord' does not contain a property with the name
ViewCount.

Source Error:


Line 69: If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Line 70: 'Snip out the ViewCount
Line 71: Dim viewCount As Integer =
Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "ViewCount"))
Line 72: viewCountSum += viewCount
Line 73: ElseIf e.Item.ItemType = ListItemType.Footer Then


Source File: c:\inetpub\wwwroot\test\Sales\j2list.aspx.vb Line: 71

Stack Trace:


[HttpException (0x80004005): DataBinder.Eval:
'System.Data.Common.DbDataRecord' does not contain a property with the name
ViewCount.]
System.Web.UI.DataBinder.GetPropertyValue(Object container, String
propName)
System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts)
System.Web.UI.DataBinder.Eval(Object container, String expression)
test.j2list.mydatagrid_itemdatabound(Object sender, DataGridItemEventArgs
e) in c:\inetpub\wwwroot\test\Sales\j2list.aspx.vb:71
System.Web.UI.WebControls.DataGrid.OnItemDataBound(DataGridItemEventArgs
e)
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource)
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
test.j2list.BindGrid() in c:\inetpub\wwwroot\test\Sales\j2list.aspx.vb:59
test.j2list.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\test\Sales\j2list.aspx.vb:49
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


The code that generates the error is here:

Public Sub mydatagrid_itemdatabound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)

If (e.Item.ItemType = ListItemType.Footer) Then

Dim rows As Integer

rows = DataGrid1.Items.Count

e.Item.Cells(6).Text = "Total Purchase Orders: (" & rows & ")"

End If

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then

'Snip out the ViewCount

Dim viewCount As Integer = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem,
"ViewCount"))

viewCountSum += viewCount

ElseIf e.Item.ItemType = ListItemType.Footer Then

'e.Item.Cells(11).Text = "Total: " & String.Format("{0:#,###}",
viewCountSum)

e.Item.Cells(11).Text = viewCountSum

End If

End Sub



If I comment out the Viewcount in the second part of the Sub, it works fine,
putting out a count in the footer of the number of rows in the datagrid.

Stepping through the code, it will go thru the if statements once on the
header, and then it'll blow up on the footer. I want to put a count of the
rows in column 6, and then put totals of columns 11, 12 & 13 in the footer.



Any ideas as to what's happening?



SC
 
G

Guest

Greg:

Thanks for the response.

How do you get a label in the footer of the datagrid?


SC

Cowboy (Gregory A. Beamer) said:
You are asking the DataBinder to evaluate the DataTable for a property
called viewCount, which is a value you have created. If you wish to bind,
you have two options.

1. Set up a label in the footer and set the value from CodeBehind. Something
like:

MyFooterLabel.Text = viewCount.ToString()

2. Use simple binding
a. Set up viewCount as a page scoped variable

Protected viewCount As Integer = 0

In you code, you continue to set as you have. Then, you bind like so (may
have to dink with syntax - I prefer the push method (#1) instead of the pull
below):

<%# =viewCount %>

If you are using DataViews, tables, et al, you have other ways of reaching
counts. With a DataReader, you can geta count after full read.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
I have gotten the following error in trying to get totals to come out on a
footer.

Server Error in '/test' Application.
--------------------------------------------------------------------------
--
----

DataBinder.Eval: 'System.Data.Common.DbDataRecord' does not contain a
property with the name ViewCount.
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: DataBinder.Eval:
'System.Data.Common.DbDataRecord' does not contain a property with the name
ViewCount.

Source Error:


Line 69: If e.Item.ItemType = ListItemType.Item Or
e.Item.ItemType
=
ListItemType.AlternatingItem Then
Line 70: 'Snip out the ViewCount
Line 71: Dim viewCount As Integer =
Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "ViewCount"))
Line 72: viewCountSum += viewCount
Line 73: ElseIf e.Item.ItemType = ListItemType.Footer Then


Source File: c:\inetpub\wwwroot\test\Sales\j2list.aspx.vb Line: 71

Stack Trace:


[HttpException (0x80004005): DataBinder.Eval:
'System.Data.Common.DbDataRecord' does not contain a property with the name
ViewCount.]
System.Web.UI.DataBinder.GetPropertyValue(Object container, String
propName)
System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts)
System.Web.UI.DataBinder.Eval(Object container, String expression)
test.j2list.mydatagrid_itemdatabound(Object sender, DataGridItemEventArgs
e) in c:\inetpub\wwwroot\test\Sales\j2list.aspx.vb:71
System.Web.UI.WebControls.DataGrid.OnItemDataBound(DataGridItemEventArgs
e)
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource)
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
test.j2list.BindGrid() in c:\inetpub\wwwroot\test\Sales\j2list.aspx.vb:59
test.j2list.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\test\Sales\j2list.aspx.vb:49
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


The code that generates the error is here:

Public Sub mydatagrid_itemdatabound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)

If (e.Item.ItemType = ListItemType.Footer) Then

Dim rows As Integer

rows = DataGrid1.Items.Count

e.Item.Cells(6).Text = "Total Purchase Orders: (" & rows & ")"

End If

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then

'Snip out the ViewCount

Dim viewCount As Integer = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem,
"ViewCount"))

viewCountSum += viewCount

ElseIf e.Item.ItemType = ListItemType.Footer Then

'e.Item.Cells(11).Text = "Total: " & String.Format("{0:#,###}",
viewCountSum)

e.Item.Cells(11).Text = viewCountSum

End If

End Sub



If I comment out the Viewcount in the second part of the Sub, it works fine,
putting out a count in the footer of the number of rows in the datagrid.

Stepping through the code, it will go thru the if statements once on the
header, and then it'll blow up on the footer. I want to put a count of the
rows in column 6, and then put totals of columns 11, 12 & 13 in the footer.



Any ideas as to what's happening?



SC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top