Solved

Databinder.Eval help: Argument 'Expression' is not a valid value. asp.net

Posted on 2007-04-10
12
2,132 Views
Last Modified: 2012-05-05
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(Container, "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(Container, "DataItem.intCancellations"),"###0.") %>'></asp:Label></td>
Line 319:                                            </tr>
Line 320:                                                                  <TR>
 


 
0
Comment
Question by:ramrodcar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 4

Expert Comment

by:CBeach1980
ID: 18884588
Is "========TOTALS: All Values================" one of the values in the dataset?
0
 
LVL 4

Expert Comment

by:CBeach1980
ID: 18884597
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.
0
 

Author Comment

by:ramrodcar
ID: 18884654
no i added that for the distinction between a normal month row and the aggregate role, it's added to the label.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:ramrodcar
ID: 18884671
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.IsDBNull(rowTemp.Item(7)), 0, rowTemp.Item(7)) '4/10
..
..
..
and add it here:
objNewRow(6) = IIf(System.Convert.IsDBNull(intCancellationUnitSum), 0, intCancellationUnitSum)
0
 

Author Comment

by:ramrodcar
ID: 18884693
but i have also tried taking away the format part of
Format(DataBinder.Eval(Container, "DataItem.intCancellations"),"###0."), and it doesn't fail
and i get nothing inbetween the <td> tags, so maybe it's null then.....
0
 
LVL 4

Expert Comment

by:CBeach1980
ID: 18884718
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.
0
 

Author Comment

by:ramrodcar
ID: 18884725
here's the whole function:
    Private Function CreateAggregateByQuarter(ByRef 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).Columns
                ds.Tables(strAggTableName).Columns.Add(New DataColumn(clmTemp.ColumnName, 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.Add(New DataColumn("txtAggDesc", System.Type.GetType("System.String")))
        Dim intAggLabelColumnIndex As Integer = ds.Tables(strAggTableName).Columns.Count - 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(intAggLabelColumnIndex) As Object

            'Sum all additive values and then add a new row when a quarter.
            Dim intRowCount As Integer = ds.Tables(strTableName).Rows.Count
            Dim intRow As Integer = 1
            Dim intStartMonth As Integer = 3
            Dim booAddRowFlag As Boolean = False

            For Each rowTemp In ds.Tables(strTableName).Rows
                'Item(0)is the date.
                intNetUnitsum += IIf(System.Convert.IsDBNull(rowTemp.Item(1)), 0, rowTemp.Item(1))
                intNetDollarsum += IIf(System.Convert.IsDBNull(rowTemp.Item(2)), 0, rowTemp.Item(2))
                intUCUnitSum += IIf(System.Convert.IsDBNull(rowTemp.Item(3)), 0, rowTemp.Item(3))
                intUSUnitSum += IIf(System.Convert.IsDBNull(rowTemp.Item(4)), 0, (rowTemp.Item(4)))

                intCancellationUnitSum += IIf(System.Convert.IsDBNull(rowTemp.Item(7)), 0, rowTemp.Item(7)) '4/10
                'intCancellationUnitSum = 234

                intUnitAllSum += IIf(System.Convert.IsDBNull(rowTemp.Item(1)), 0, rowTemp.Item(1))
                intDollarAllSum += IIf(System.Convert.IsDBNull(rowTemp.Item(2)), 0, rowTemp.Item(2))
                intUCUnitAllSum += IIf(System.Convert.IsDBNull(rowTemp.Item(3)), 0, rowTemp.Item(3))
                intUSUnitAllSum += IIf(System.Convert.IsDBNull(rowTemp.Item(4)), 0, (rowTemp.Item(4)))

                intCancellationUnitAllSum += IIf(System.Convert.IsDBNull(rowTemp.Item(7)), 0, rowTemp.Item(7)) '4/10

                Select Case (CDate(rowTemp.Item(0)).Month 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(intAggLabelColumnIndex) = CDate(rowTemp.Item(0)).ToShortDateString + " 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(intAggLabelColumnIndex) = CDate(rowTemp.Item(0)).ToShortDateString + " Only"
                                Else
                                    objNewRow(intAggLabelColumnIndex) = CDate(rowTemp.Item(0)).AddMonths(-1).ToShortDateString + " to " + CDate(rowTemp.Item(0)).ToShortDateString + " 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(intAggLabelColumnIndex) = CDate(rowTemp.Item(0)).Year.ToString + "Q" + Fix(CDate(rowTemp.Item(0)).Month / 3).ToString
                                'objnewrow(intAggLabelColumnIndex) = CDate(rowTemp.Item(0)).AddMonths(-2).ToShortDateString + " to " + CDate(rowTemp.Item(0)).ToShortDateString
                            Case 2  'The rows represent the last two months in the quarter
                                objNewRow(intAggLabelColumnIndex) = CDate(rowTemp.Item(0)).AddMonths(-1).ToShortDateString + " to " + CDate(rowTemp.Item(0)).ToShortDateString + " Only"
                            Case Else  'It's the first and last row
                                objNewRow(intAggLabelColumnIndex) = CDate(rowTemp.Item(0)).ToShortDateString + " 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.IsDBNull(intCancellationUnitSum), 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(intCancellationUnitAllSum, 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(intAggLabelColumnIndex) = "Period Sum"
            ds.Tables(strAggTableName).Rows.Add(objNewRow)
            Return strAggTableName
0
 
LVL 4

Expert Comment

by:CBeach1980
ID: 18884774
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.
0
 

Author Comment

by:ramrodcar
ID: 18884839
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.
0
 
LVL 4

Accepted Solution

by:
CBeach1980 earned 500 total points
ID: 18884898
That's fine but assigning the values by index causes the last 2 columns to be empty which happens to include the intCancellations column.  You'd need to either assign to all the indicies, assign the values by column name, or remove the unnecessary columns from the table so that you are assigning to each index.

---------------------
'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.IsDBNull(intCancellationUnitSum), 0,intCancellationUnitSum) '4/10 'before lunch
0
 

Author Comment

by:ramrodcar
ID: 18884944
Thank you very much sir, hit the nail right on the head.
0
 
LVL 4

Expert Comment

by:CBeach1980
ID: 18884955
My pleasure.  Glad to be of help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question