locked
getting row index of repeater error RRS feed

  • Question

  • User1717218719 posted

    Error:

    conversion from string type "system.Data.DataRowView" to type 'integer' is not valid.

    On the line:

    Dim intIdx As Integer = CType(e.CommandSource, LinkButton).CommandArgument

    Private Sub rptTaxCom_ItemCommand(source As Object, e As RepeaterCommandEventArgs) Handles rptTaxCom.ItemCommand
    
            Try
    
                If CType(e.CommandSource, LinkButton).CommandName = "UpdateRow" Then
    
                    Dim intIdx As Integer = CType(e.CommandSource, LinkButton).CommandArgument
    
                    Dim itmRpt As RepeaterItem = Me.rptTaxCom.Items(intIdx)
    
                    CType(itmRpt.FindControl("TextBox4"), TextBox).Text = CType(itmRpt.FindControl("TextBox2"), TextBox).Text - CType(itmRpt.FindControl("TextBox3"), TextBox).Text
    
                End If
    
    
                '-- Update footer totals
                CType(Me.rptTaxCom.Items(Me.rptTaxCom.Items.Count - 1).FindControl("Label1"), Label).Text = "5555"
    
    
    
            Catch ex As Exception
                MsgBox("Error:  " & ex.Message & ex.StackTrace)
    
            End Try
    
        End Sub
    <asp:LinkButton ID="lnkUpdate" Text="Update" runat="server" CommandName="UpdateRow" CommandArgument='<%# Container.DataItemIndex %>' />



    Thursday, June 13, 2019 12:25 PM

Answers

  • User-719153870 posted

    Hi E.RU,

    This error indicates that you can't assign system.Data.DataRowView-type data directly to int-type variables.

    I recommend that you use the mandatory transformation method. In vb, you can use the CInt(expression) method.

    Please refer to the following code:

    Dim intIdx As Integer =Cint( CType(e.CommandSource, LinkButton).CommandArgument)

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 14, 2019 3:06 AM