Results 1 to 8 of 8
  1. #1
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Warrington, Cheshire
    Posts
    355
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Sorting a table (.net)

    I am currently using sort on tables and get the following error message when I select the header field:
    No accessible overloaded 'Math.Round' can be called without a narrowing conversion

    I am using exactly the same coding (apart from table names) on anpother subsequent page with no problems.
    Any suggestions?
    Is it trying to deal with null or nothing values and getting confused?
    The code lifted straight from the page is:
    <pre> Sub Clients_sort(ByVal s As Object, ByVal e As DataGridSortCommandEventArgs) _
    Handles DGClientSummaryGroup.SortCommand
    ' Retrieve the data source from session state.
    Dim dt As DataTable = CType(Session("ClientSource"), DataTable)
    ' Create a DataView from the DataTable.
    Dim dv As DataView = New DataView(dt)
    ' The DataView provides an easy way to sort. Simply set the Sort property with
    ' the name of the field to sort by.
    dv.Sort = e.SortExpression
    ' Re-bind the data source and specify that it should be sorted
    ' by the field specified in the SortExpression property.
    DGClientSummaryGroup.DataSource = dv
    DGClientSummaryGroup.DataBind()
    End Sub
    </pre>



    cheers
    Alan

  2. #2
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Warrington, Cheshire
    Posts
    355
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Sorting a table (.net)

    By a process of elimination I can now see that the error is occurring as a result of trying to sort a negative number in a list.
    The sorting function is working fine when there are no negative numbers in my whole column - but how can I deal with negatives as part of the following function:
    <pre>math.round(myTable.compute(myval,""),0)
    </pre>


    TIA
    Alan

  3. #3
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Sorting a table (.net)

    I'm confused. The Compute function is supposed to calculate an aggregate function. Math.Round shouldn't have an issue with negative numbers (except possibly in where you think the rounding should occur) Can you clarify exactly what is going on in your code?
    Regards,
    Rory

    Microsoft MVP - Excel

  4. #4
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Warrington, Cheshire
    Posts
    355
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Sorting a table (.net)

    First line of the exception is:

    [AmbiguousMatchException: No accessible overloaded 'Math.Round' can be called without a narrowing conversion.]

    I have a client list returned and values which can fall into negative
    The list is 10 columns wide, of wich only one column is alpha - the remaining columns being either integer or decimal percent
    The list comes back fine and is sorted by way of ORDER BY in the select statement.
    In a list which contains maybe 15 rows, and no negative values in any of the columns, the sort works fine.
    In a list of 15 rows where one of the columns contains one cell at negative - I get the error.
    How can this be? The math.round like you say works fine with negative numbers at the initial creation of the page.

    Once I retrieve my data i have totals via the math.round and also the introduction of another column to give the percent of the total value for each row
    <pre>'add a new column to indicate the % total turnover of the ytd values
    strYTDMarg = "Ysales/" & myTableClients.Compute("Sum(Ysales)", "") / 100
    myTableClients.Columns.Add(New DataColumn("YTD Percent", _
    GetType(Decimal), strYTDMarg))
    </pre>

    But that's not my math.round

    Just checked another client and the error is occurring when all positives - so got to look elsewhere too.


    Alan

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Sorting a table (.net)

    This appears to indicate that you are converting something large to something small that cannot handle it. However, do you have any Null values that are not being handled in these datasets?
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Warrington, Cheshire
    Posts
    355
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Sorting a table (.net)

    Spot on with the Null Rory, although in a kind of tenuous link way.
    The null was arising because I got caught out and wasn't reading exactly what was happening.
    Yes there's a null - because I am returning no values - because the onsortcommand is not going to my onsortcommand sub but is instead going to my drill_down sub which redirects my page (with responses) to a completely differnet page.
    The new page was looking for parameters which weren't there and hence no values returned.
    Just gotta step through my page now and check the links:

    In my grid def I have: OnSortCommand="Clients_Sort"
    and also
    OnItemCommand="Link_Command"
    The onsortexpression for each column is set to the datafield

    My final column is a button column which contains:
    CommandName="Workers_Command"

    That seems to have been where the problem is.

    I have added the following to catch the Workers_Command button in my Links_Command sub:
    If CType(e.CommandSource, Button).CommandName = "Workers_command" Then

    so it SHOULD catch my button press command - but it doesn't!?

    Getting confused and need to sit back for a while.

    Cheers
    Alan

  7. #7
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Warrington, Cheshire
    Posts
    355
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Sorting a table (.net)

    I have this as my button column:
    <pre><asp:buttoncolumn
    CommandName="Workers_Command"
    runat="server"
    ButtonType="linkButton"
    ItemStyle-HorizontalAlign="center"
    ItemStyle-Font-Size="5"
    text="SELECT"
    Headertext="Drill
    down">
    </asp:buttoncolumn>
    </pre>


    which should be caught by my line of:
    <pre>If e.CommandName = "Workers_command" Then
    Dim strURL As String
    Dim strClient As String
    Dim clientCell As TableCell = e.Item.Cells(1)

    strClient = clientCell.Text
    strURL = "GMWorkers.aspx?id=" & strClient
    strURL &= "&ledger=" & Request.QueryString("ledger")
    strURL &= "&prevledger=" & Request.QueryString("prevledger")
    strURL &= "&year=" & Request.QueryString("year")
    strURL &= "&prevYear=" & Request.QueryString("PrevYear")

    Response.Redirect(strURL)
    Else

    End If</pre>


    my grid def is:
    <pre><asp:datagrid id="DGClientSummaryGroup"
    runat="server"
    Width="95%"
    ShowFooter="True"
    ForeColor="Black"
    AutoGenerateColumns="False"
    AllowSorting="True"
    OnSortCommand="Clients_Sort"
    OnItemCommand="Link_Command" ></pre>


    NOW, when I select the header field I get the table sorted.
    When I mouse click the "SELECT" column text I still get the table sorted and not redirected to my new page.
    If I take the If statement ("If e.commandName=..... ") out then it tries to redirect every time I select either a column heading or the SELECT text.
    And when it redirects it sends the wrong response values hence the math.round original error.

    Round in circles is what it feels like.
    Alan

  8. #8
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Warrington, Cheshire
    Posts
    355
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Sorting a table (.net)

    I have not changed from my last code but for some reason it is now working. Could have been a cache?
    The If statement now catches the command name and redirects or not.

    Cheers for the help...but.....I have another prob for posting separate.

    TIA
    Alan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •