ramrodcar
asked on
Databinder.Eval help: Argument 'Expression' is not a valid value. asp.net
I have a page that i'm updating that has several Databinder.Eval on a dataset created in the code behind. I've subsequently added a few more fields of output to the SP, and they show correctly in the dataset on the page when i loop through them.
My page has information on a month by month basis in table 1
The page creates an quarterly aggregate and drops it in table 2 based off of the table 1 dataset.
This is the statement that is bombing it:
Format(DataBinder.Eval(Con tainer, "DataItem.intCancellations "),"###0." )
This same exact statement is being used in an item template with a data list and it works in the first table. When i try and use this same statement, which has all of the same column names in the second datalist it bombs. All of the column names are the same and are of the same format.
the data types in the temporary table here:
dttMonthFirstDay System.DateTime
intNetiUnits System.Int32
intNetDollars System.Int32
intUCUnits System.Int32
intUSUnits System.Double
dblUnitMS System.Double
intMonthID System.Int32
intCancellations System.Int32
intGrossUnits System.Int32
with the data being here, the last digit is cancellations, so for instance this would be January and February, with it creating a partial aggregate record for the two months.
1/1/1950 12:00:00 AM 4 466000 35 54 0.0740740740740741 1
1/1/1950 12:00:00 AM 10 988180 30 76 0.131578947368421 0
========TOTALS: All Values================
1/1/1950 12:00:00 AM 14 1454180 65 130 0.107692307692308 1
here's the stack
Source Error:
Line 316: <tr>
Line 317: <td align="middle">
Line 318: <asp:Label ID="lblCancellationUnits" runat="server" Text='<%# Format(DataBinder.Eval(Con tainer, "DataItem.intCancellations "),"###0." ) %>'></asp:Label></td>
Line 319: </tr>
Line 320: <TR>
My page has information on a month by month basis in table 1
The page creates an quarterly aggregate and drops it in table 2 based off of the table 1 dataset.
This is the statement that is bombing it:
Format(DataBinder.Eval(Con
This same exact statement is being used in an item template with a data list and it works in the first table. When i try and use this same statement, which has all of the same column names in the second datalist it bombs. All of the column names are the same and are of the same format.
the data types in the temporary table here:
dttMonthFirstDay System.DateTime
intNetiUnits System.Int32
intNetDollars System.Int32
intUCUnits System.Int32
intUSUnits System.Double
dblUnitMS System.Double
intMonthID System.Int32
intCancellations System.Int32
intGrossUnits System.Int32
with the data being here, the last digit is cancellations, so for instance this would be January and February, with it creating a partial aggregate record for the two months.
1/1/1950 12:00:00 AM 4 466000 35 54 0.0740740740740741 1
1/1/1950 12:00:00 AM 10 988180 30 76 0.131578947368421 0
========TOTALS: All Values================
1/1/1950 12:00:00 AM 14 1454180 65 130 0.107692307692308 1
here's the stack
Source Error:
Line 316: <tr>
Line 317: <td align="middle">
Line 318: <asp:Label ID="lblCancellationUnits" runat="server" Text='<%# Format(DataBinder.Eval(Con
Line 319: </tr>
Line 320: <TR>
Is "========TOTALS: All Values================" one of the values in the dataset?
If so the problem is with the data because for that row the intCancellations column is probably NULL which will get upset if you try and format it into an number.
ASKER
no i added that for the distinction between a normal month row and the aggregate role, it's added to the label.
ASKER
it shouldn't be null, it happens if i hard code a number into the recordset, also i check for null here:
intCancellationUnitSum += IIf(System.Convert.IsDBNul l(rowTemp. Item(7)), 0, rowTemp.Item(7)) '4/10
..
..
..
and add it here:
objNewRow(6) = IIf(System.Convert.IsDBNul l(intCance llationUni tSum), 0, intCancellationUnitSum)
intCancellationUnitSum += IIf(System.Convert.IsDBNul
..
..
..
and add it here:
objNewRow(6) = IIf(System.Convert.IsDBNul
ASKER
but i have also tried taking away the format part of
Format(DataBinder.Eval(Con tainer, "DataItem.intCancellations "),"###0." ), and it doesn't fail
and i get nothing inbetween the <td> tags, so maybe it's null then.....
Format(DataBinder.Eval(Con
and i get nothing inbetween the <td> tags, so maybe it's null then.....
Try stepping through the data in debug mode and make sure the value is a number. It could be a blank string instead of null which would cause it to miss your IsDBNull check and yet still have a problem with formatting.
ASKER
here's the whole function:
Private Function CreateAggregateByQuarter(B yRef ds As DataSet, ByVal strTableName As String) As String
'Column 0 must be date type for this routine to work.
Dim strAggTableName As String = strTableName + "_AggByQtr"
ds.Tables.Add(New DataTable(strAggTableName) )
'Define the new table with the same dimensions as the base table.
Dim clmTemp As DataColumn
For Each clmTemp In ds.Tables(strTableName).Co lumns
ds.Tables(strAggTableName) .Columns.A dd(New DataColumn(clmTemp.ColumnN ame, clmTemp.DataType))
Label1.Text += clmTemp.ColumnName & " " & clmTemp.DataType.ToString & "<BR>"
Next
Label1.Text += "<BR>"
'Add a new column to hold text description of the aggregate.
ds.Tables(strAggTableName) .Columns.A dd(New DataColumn("txtAggDesc", System.Type.GetType("Syste m.String") ))
Dim intAggLabelColumnIndex As Integer = ds.Tables(strAggTableName) .Columns.C ount - 1
'Aggregate the values and place them into the new table.
'This is where this function must be customized for the dataset.
Dim rowTemp As DataRow
Dim itmTemp As Object
Dim intNetUnitsum As Integer = 0
Dim intNetDollarsum As Integer = 0
Dim intUCUnitSum As Integer = 0
Dim intUSUnitSum As Integer = 0
Dim intCancellationUnitSum As Integer = 0 '4/10
Dim intUnitAllSum As Integer = 0
Dim intDollarAllSum As Integer = 0
Dim intUCUnitAllSum As Integer = 0
Dim intUSUnitAllSum As Integer = 0
Dim intCancellationUnitAllSum As Integer = 0 '4/10
Dim objNewRow(intAggLabelColum nIndex) As Object
'Sum all additive values and then add a new row when a quarter.
Dim intRowCount As Integer = ds.Tables(strTableName).Ro ws.Count
Dim intRow As Integer = 1
Dim intStartMonth As Integer = 3
Dim booAddRowFlag As Boolean = False
For Each rowTemp In ds.Tables(strTableName).Ro ws
'Item(0)is the date.
intNetUnitsum += IIf(System.Convert.IsDBNul l(rowTemp. Item(1)), 0, rowTemp.Item(1))
intNetDollarsum += IIf(System.Convert.IsDBNul l(rowTemp. Item(2)), 0, rowTemp.Item(2))
intUCUnitSum += IIf(System.Convert.IsDBNul l(rowTemp. Item(3)), 0, rowTemp.Item(3))
intUSUnitSum += IIf(System.Convert.IsDBNul l(rowTemp. Item(4)), 0, (rowTemp.Item(4)))
intCancellationUnitSum += IIf(System.Convert.IsDBNul l(rowTemp. Item(7)), 0, rowTemp.Item(7)) '4/10
'intCancellationUnitSum = 234
intUnitAllSum += IIf(System.Convert.IsDBNul l(rowTemp. Item(1)), 0, rowTemp.Item(1))
intDollarAllSum += IIf(System.Convert.IsDBNul l(rowTemp. Item(2)), 0, rowTemp.Item(2))
intUCUnitAllSum += IIf(System.Convert.IsDBNul l(rowTemp. Item(3)), 0, rowTemp.Item(3))
intUSUnitAllSum += IIf(System.Convert.IsDBNul l(rowTemp. Item(4)), 0, (rowTemp.Item(4)))
intCancellationUnitAllSum += IIf(System.Convert.IsDBNul l(rowTemp. Item(7)), 0, rowTemp.Item(7)) '4/10
Select Case (CDate(rowTemp.Item(0)).Mo nth Mod 3)
Case 1 '1,4,7,10 ==> First month in a quarter
Select Case intRow
Case intRowCount 'It's the last row, so create the proper row label.
booAddRowFlag = True
objNewRow(intAggLabelColum nIndex) = CDate(rowTemp.Item(0)).ToS hortDateSt ring + " Only"
Case 1
intStartMonth = 1
End Select
Case 2 '2,5,8,11 ==> Second month in a quarter
Select Case intRow
Case intRowCount 'It's the last row, so create the proper row label.
booAddRowFlag = True
If intRowCount = 1 Then 'It's the first and last row
objNewRow(intAggLabelColum nIndex) = CDate(rowTemp.Item(0)).ToS hortDateSt ring + " Only"
Else
objNewRow(intAggLabelColum nIndex) = CDate(rowTemp.Item(0)).Add Months(-1) .ToShortDa teString + " to " + CDate(rowTemp.Item(0)).ToS hortDateSt ring + " Only"
End If
Case 1
intStartMonth = 2
End Select
Case 0 '3,6,9,12 ==> Third month in a quarter
booAddRowFlag = True 'Add a new row regardless.
Select Case intStartMonth
Case 1 'Normal quarter with all three rows added.
objNewRow(intAggLabelColum nIndex) = CDate(rowTemp.Item(0)).Yea r.ToString + "Q" + Fix(CDate(rowTemp.Item(0)) .Month / 3).ToString
'objnewrow(intAggLabelColu mnIndex) = CDate(rowTemp.Item(0)).Add Months(-2) .ToShortDa teString + " to " + CDate(rowTemp.Item(0)).ToS hortDateSt ring
Case 2 'The rows represent the last two months in the quarter
objNewRow(intAggLabelColum nIndex) = CDate(rowTemp.Item(0)).Add Months(-1) .ToShortDa teString + " to " + CDate(rowTemp.Item(0)).ToS hortDateSt ring + " Only"
Case Else 'It's the first and last row
objNewRow(intAggLabelColum nIndex) = CDate(rowTemp.Item(0)).ToS hortDateSt ring + " Only"
End Select
End Select
If booAddRowFlag Then
booAddRowFlag = False ' Reset the flag
'Add the values to the table
objNewRow(0) = #1/1/1950# 'Cannot use DBNull.Value because it will generate an error. But this should never be shown anyway.
objNewRow(1) = intNetUnitsum
objNewRow(2) = intNetDollarsum
objNewRow(3) = intUCUnitSum
objNewRow(4) = intUSUnitSum
objNewRow(5) = IIf(intUSUnitSum, intNetUnitsum / intUSUnitSum, 0)
objNewRow(6) = IIf(System.Convert.IsDBNul l(intCance llationUni tSum), 0, intCancellationUnitSum) '4/10 'before lunch
ds.Tables(strAggTableName) .Rows.Add( objNewRow)
Label1.Text += "<BR>"
Label1.Text += strTableName & " "
Dim k As Integer
For k = 0 To 6
Label1.Text += objNewRow(k).ToString & " "
Next k
'Zero the agg variables
intNetUnitsum = 0
intNetDollarsum = 0
intUCUnitSum = 0
intUSUnitSum = 0
intCancellationUnitSum = 0
'Reset the start month status each time you add a row to the table
intStartMonth = 1
End If
intRow += 1
Next
'Add the "all" values to the table
objNewRow(0) = #1/1/1950# 'Cannot use DBNull.Value because it will generate an error. But this should never be shown anyway.
objNewRow(1) = intUnitAllSum
objNewRow(2) = intDollarAllSum
objNewRow(3) = intUCUnitAllSum
objNewRow(4) = intUSUnitAllSum
objNewRow(5) = IIf(intUSUnitAllSum, intUnitAllSum / intUSUnitAllSum, 0)
objNewRow(6) = IIf(intCancellationUnitAll Sum, intCancellationUnitAllSum, 0) '4/10
Label1.Text += "<br/>========TOTALS: All Values================<BR> "
Dim i As Integer
For i = 0 To 6
Label1.Text += objNewRow(i).ToString & " "
Next i
Label1.Text += "<BR><br>"
objNewRow(intAggLabelColum nIndex) = "Period Sum"
ds.Tables(strAggTableName) .Rows.Add( objNewRow)
Return strAggTableName
Private Function CreateAggregateByQuarter(B
'Column 0 must be date type for this routine to work.
Dim strAggTableName As String = strTableName + "_AggByQtr"
ds.Tables.Add(New DataTable(strAggTableName)
'Define the new table with the same dimensions as the base table.
Dim clmTemp As DataColumn
For Each clmTemp In ds.Tables(strTableName).Co
ds.Tables(strAggTableName)
Label1.Text += clmTemp.ColumnName & " " & clmTemp.DataType.ToString & "<BR>"
Next
Label1.Text += "<BR>"
'Add a new column to hold text description of the aggregate.
ds.Tables(strAggTableName)
Dim intAggLabelColumnIndex As Integer = ds.Tables(strAggTableName)
'Aggregate the values and place them into the new table.
'This is where this function must be customized for the dataset.
Dim rowTemp As DataRow
Dim itmTemp As Object
Dim intNetUnitsum As Integer = 0
Dim intNetDollarsum As Integer = 0
Dim intUCUnitSum As Integer = 0
Dim intUSUnitSum As Integer = 0
Dim intCancellationUnitSum As Integer = 0 '4/10
Dim intUnitAllSum As Integer = 0
Dim intDollarAllSum As Integer = 0
Dim intUCUnitAllSum As Integer = 0
Dim intUSUnitAllSum As Integer = 0
Dim intCancellationUnitAllSum As Integer = 0 '4/10
Dim objNewRow(intAggLabelColum
'Sum all additive values and then add a new row when a quarter.
Dim intRowCount As Integer = ds.Tables(strTableName).Ro
Dim intRow As Integer = 1
Dim intStartMonth As Integer = 3
Dim booAddRowFlag As Boolean = False
For Each rowTemp In ds.Tables(strTableName).Ro
'Item(0)is the date.
intNetUnitsum += IIf(System.Convert.IsDBNul
intNetDollarsum += IIf(System.Convert.IsDBNul
intUCUnitSum += IIf(System.Convert.IsDBNul
intUSUnitSum += IIf(System.Convert.IsDBNul
intCancellationUnitSum += IIf(System.Convert.IsDBNul
'intCancellationUnitSum = 234
intUnitAllSum += IIf(System.Convert.IsDBNul
intDollarAllSum += IIf(System.Convert.IsDBNul
intUCUnitAllSum += IIf(System.Convert.IsDBNul
intUSUnitAllSum += IIf(System.Convert.IsDBNul
intCancellationUnitAllSum += IIf(System.Convert.IsDBNul
Select Case (CDate(rowTemp.Item(0)).Mo
Case 1 '1,4,7,10 ==> First month in a quarter
Select Case intRow
Case intRowCount 'It's the last row, so create the proper row label.
booAddRowFlag = True
objNewRow(intAggLabelColum
Case 1
intStartMonth = 1
End Select
Case 2 '2,5,8,11 ==> Second month in a quarter
Select Case intRow
Case intRowCount 'It's the last row, so create the proper row label.
booAddRowFlag = True
If intRowCount = 1 Then 'It's the first and last row
objNewRow(intAggLabelColum
Else
objNewRow(intAggLabelColum
End If
Case 1
intStartMonth = 2
End Select
Case 0 '3,6,9,12 ==> Third month in a quarter
booAddRowFlag = True 'Add a new row regardless.
Select Case intStartMonth
Case 1 'Normal quarter with all three rows added.
objNewRow(intAggLabelColum
'objnewrow(intAggLabelColu
Case 2 'The rows represent the last two months in the quarter
objNewRow(intAggLabelColum
Case Else 'It's the first and last row
objNewRow(intAggLabelColum
End Select
End Select
If booAddRowFlag Then
booAddRowFlag = False ' Reset the flag
'Add the values to the table
objNewRow(0) = #1/1/1950# 'Cannot use DBNull.Value because it will generate an error. But this should never be shown anyway.
objNewRow(1) = intNetUnitsum
objNewRow(2) = intNetDollarsum
objNewRow(3) = intUCUnitSum
objNewRow(4) = intUSUnitSum
objNewRow(5) = IIf(intUSUnitSum, intNetUnitsum / intUSUnitSum, 0)
objNewRow(6) = IIf(System.Convert.IsDBNul
ds.Tables(strAggTableName)
Label1.Text += "<BR>"
Label1.Text += strTableName & " "
Dim k As Integer
For k = 0 To 6
Label1.Text += objNewRow(k).ToString & " "
Next k
'Zero the agg variables
intNetUnitsum = 0
intNetDollarsum = 0
intUCUnitSum = 0
intUSUnitSum = 0
intCancellationUnitSum = 0
'Reset the start month status each time you add a row to the table
intStartMonth = 1
End If
intRow += 1
Next
'Add the "all" values to the table
objNewRow(0) = #1/1/1950# 'Cannot use DBNull.Value because it will generate an error. But this should never be shown anyway.
objNewRow(1) = intUnitAllSum
objNewRow(2) = intDollarAllSum
objNewRow(3) = intUCUnitAllSum
objNewRow(4) = intUSUnitAllSum
objNewRow(5) = IIf(intUSUnitAllSum, intUnitAllSum / intUSUnitAllSum, 0)
objNewRow(6) = IIf(intCancellationUnitAll
Label1.Text += "<br/>========TOTALS: All Values================<BR>
Dim i As Integer
For i = 0 To 6
Label1.Text += objNewRow(i).ToString & " "
Next i
Label1.Text += "<BR><br>"
objNewRow(intAggLabelColum
ds.Tables(strAggTableName)
Return strAggTableName
Your data dump from the top doesn't have the same number of values as you have columns. You only have 7 values and 9 columns so the intCancellations and intGrossUnits both appear to be null.
ASKER
the second table doesn't need 9 values, it only needs the 7, this second table doesn't use all the values from the other datalists dataset.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much sir, hit the nail right on the head.
My pleasure. Glad to be of help.