Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 998189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:09:13+00:00 2026-05-16T07:09:13+00:00

I am trying to add a new row into a gridview but for some

  • 0

I am trying to add a new row into a gridview but for some reason i’m having a problem in the for loop.

Directly goes to dtCurrentTable.Rows.Add(drCurrentRow) and of course, have an error “‘row’ argument cannot be null.Parameter name: row”, because the dtcurrentTable.NewRow was not executed.

Why is this happening?

 Private Sub AddNewRowToGrid()
    Dim rowIndex As Integer = 0
    If Not IsNothing(ViewState("CurrentTable")) Then

        Dim dtCurrentTable As DataTable = CType(ViewState("CurrentTable"), DataTable)
        Dim drCurrentRow As DataRow = Nothing

        If dtCurrentTable.Rows.Count > 0 Then
            For i as Integer = 1 To i <= dtCurrentTable.Rows.Count
                ' Extraem-se os valores das Textbox
                Dim box1 As TextBox = Dados.Rows(rowIndex).Cells(0).FindControl("Artigo")
                Dim box2 As TextBox = Dados.Rows(rowIndex).Cells(1).FindControl("Descricao")
                Dim box3 As TextBox = Dados.Rows(rowIndex).Cells(2).FindControl("IVA")
                Dim box4 As TextBox = Dados.Rows(rowIndex).Cells(3).FindControl("PU")
                Dim box5 As TextBox = Dados.Rows(rowIndex).Cells(4).FindControl("Desconto")
                Dim box6 As TextBox = Dados.Rows(rowIndex).Cells(5).FindControl("UN")
                Dim box7 As TextBox = Dados.Rows(rowIndex).Cells(6).FindControl("Quantidade")
                Dim box8 As TextBox = Dados.Rows(rowIndex).Cells(7).FindControl("TotalLiquido")

                drCurrentRow = dtCurrentTable.NewRow

                dtCurrentTable.Rows(i - 1)("Artigo") = box1.Text
                dtCurrentTable.Rows(i - 1)("Descricao") = box2.Text
                dtCurrentTable.Rows(i - 1)("IVA") = box3.Text
                dtCurrentTable.Rows(i - 1)("PU") = box4.Text
                dtCurrentTable.Rows(i - 1)("Desconto") = box5.Text
                dtCurrentTable.Rows(i - 1)("UN") = box6.Text
                dtCurrentTable.Rows(i - 1)("Quantidade") = box7.Text
                dtCurrentTable.Rows(i - 1)("TotalLiquido") = box8.Text

                rowIndex += 1

            Next i
            dtCurrentTable.Rows.Add(drCurrentRow)
            ViewState("CurrentTable") = dtCurrentTable

            Dados.DataSource = dtCurrentTable
            Dados.DataBind()

        End If

    Else
        Response.Write("ViewState null")
    End If
    SetPreviousData()
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:09:13+00:00Added an answer on May 16, 2026 at 7:09 am

    Your For loop is defined wrong, thats why you’re getting an error:

    For i as Integer = 1 To i <= dtCurrentTable.Rows.Count
    evaluates to
    For i as Integer = 1 To True
    (because i is always <= Rows.Count)
    which VB translates as
    For i as Integer = 1 To -1
    which means your loop never runs.

    It
    should be

    For i as Integer = 1 To dtCurrentTable.Rows.Count

    Also, there’s something odd about the way you use drCurrentRow = dtCurrentTable.NewRow. Why is that inside the loop when you don’t do anything with it in the loop? It gets executed multiple times and then dtCurrentTable.Rows.Add(drCurrentRow) only gets called once.

    Its hard for me to correct because I can’t figure out what you’re trying to do, but that bit looks dodgy to me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a <table> that has a header row. I'm trying to add an
Trying to do the following: animTimeChange = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); itemTime.startAnimation(animTimeChange); itemTime.setText(new text); but the
I am trying to add a new work item type. Where the heck are
I am trying to add a new Font to FOP. I start creating a
I'm creating a trace listener like this: // Setup log tracing. Trace.Listeners.Add(new TextWriterTraceListener(MyLogPath)); Trace.AutoFlush
I am trying to design a data warehouse for a licensing vendor, who sells
I currently trying to use an Object Relational Mapper for CodeIgniter and I'm experiencing
I'm trying to create a pdf report using iTextSharp and I'm stumped as to
I'm trying to create a grid of JButtons , with index values to the
I am trying to call an RPG program on our AS/400 machine using OleDb.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.