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 6335705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:54:30+00:00 2026-05-24T18:54:30+00:00

I am trying to loop through my repeater control and get the textbox values.

  • 0

I am trying to loop through my repeater control and get the textbox values.
However, I am getting an error:

{“Object reference not set to an instance of an object.”}

my code is:

    Dim txtField As TextBox
    Dim j As Integer = 0

   'Confirm if user has entered atleast one quantity
    For Each item In rptRequestForm.Items
        txtField = rptRequestForm.FindControl("txtBox")
        If txtField.Text <> Nothing Then
            j += 1
        Else

        End If
    Next

UPDATE: aspx code is:

        <td><asp:Repeater ID="rptRequestForm" runat="server">
            <HeaderTemplate>
                    <table border="0" width="100%">
                        <tr>
                            <td style="width:50%" class="TextFontBold"><asp:Label runat="server" ID="Label1" Text="Product"></asp:Label></td>
                            <td style="width:25%" class="TextFontBold"><asp:Label runat="server" ID="Label2" Text="Quantity"></asp:Label></td>
                            <td style="width:25%" class="TextFontBold"><asp:Label runat="server" ID="Label3" Text="Price (ea.)"></asp:Label></td>
                        </tr>
                    </table>
            </HeaderTemplate>
                <ItemTemplate>
                    <table border="0" width="100%">
                        <tr>
                            <td style="width:50%" class="TextFont"><span><%#Trim(Eval("Product_Title"))%></span></td>
                            <td style="width:25%"><asp:TextBox ID="txtBox" runat="server" Width="30%" onblur="Javascript:numberonly(this)"></asp:TextBox></td>
                            <td style="width:25%" class="TextFont"><span><%#Trim(FormatCurrency(Eval("Price")))%></span></td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:Repeater>
  • 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-24T18:54:30+00:00Added an answer on May 24, 2026 at 6:54 pm

    try

    Dim someString as String = "Not set"  <-- used later to hold the values of the string
    Dim txtField As TextBox    
    Dim j As Integer = 0   
    'Confirm if user has entered atleast one quantity    
    For Each item In rptRequestForm.Items        
       txtField = item.FindControl("txtBox")        
       If Not IsNothing(txtField) Then      ' <--- this is the line I changed       
         j += 1  
         someString = txtField.Text ' <--  once you've checked and know that the textbox exists, you just grab the value like so. 
         ' do whatever you like with the contents of someString now.     
       Else        
       End If    
    Next
    

    The problem is that you’re trying to access the “.Text” property of a TextBox that it didn’t find. The TextBox itself is the object to which there is no reference.

    Incidentally, the .Text property of an actual Textbox (one that exists and was found) can’t be “Nothing”. It can only be String.Empty or a valid string.

    Edited my line of code

    Sorry, my VB is rusty.

    Final edit

    AARGH! I’m blind. I can’t believe I didn’t see this. There were TWO problems withthe original code. This is the answer to the second issue:

    Change

    txtField = rptRequestForm.FindControl("txtBox")
    

    to

    txtField = item.FindControl("txtBox")
    

    The ITEM has to find the control, not the repeater itself!

    I created a small web app just to check to see if I was grabbing the textbox’s text and finally found the issue above. my code is NOT the same as yours in the aspx, but here’s a complete code listing so that you can see how it works:

    vb code

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            Dim t As New System.Data.DataTable
    
            t.Columns.Add("Name")
    
            Dim newRow(1) As Object
    
            t.Rows.Add(New Object() {"Frank"})
            t.Rows.Add(New Object() {"Dave"})
            t.Rows.Add(New Object() {"Muhammad"})
    
            rptRequestForm.DataSource = t
            rptRequestForm.DataBind()
    
            Dim txtField As TextBox
            Dim j As Integer = 0   'Confirm if user has entered atleast one quantity    
            For Each item As RepeaterItem In rptRequestForm.Items
                txtField = item.FindControl("txtBox")
                If Not IsNothing(txtField) Then     ' <--- this is the line I changed            
                    j += 1
                    System.Diagnostics.Debug.WriteLine(item.ItemType.ToString())
                    System.Diagnostics.Debug.WriteLine(txtField.Text)
                Else
                    System.Diagnostics.Debug.WriteLine(item.ItemType.ToString())
                End If
            Next
    End Sub
    

    aspx code

    <asp:Repeater ID="rptRequestForm" runat="server">
            <HeaderTemplate>
                Hello!
            </HeaderTemplate>
            <ItemTemplate>
                <asp:TextBox ID="txtBox" runat="server" Text='<%#Bind("Name") %>'></asp:TextBox>
                <br />
            </ItemTemplate>
    </asp:Repeater>
    

    produces the following output in the System.Diagnostics.Debug window:

    Item

    Frank

    AlternatingItem

    Dave

    Item

    Muhammad

    The thread 0x321c has exited with code 0 (0x0).

    The thread 0x39b8 has exited with code 0 (0x0).

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

Sidebar

Related Questions

I'm trying to loop through the results from the Last.fm API but it's not
I'm trying to use openmp to multithread a loop through std::set. When I write
I'm trying to loop through an array of strings using the foreach control, and
I am trying to loop through a set of ImageViews to add listeners, I
I'm trying to loop through an object with JavaScript and add all the subobjects
I'm trying to loop through Atom feed entries, and get the title attribute lets
I'm trying to loop through my totals in order to get a grand total
I'm trying to loop through a set of cells using VBA in a worksheet
I am trying to loop through a query string and pull out certain values
Im trying to loop through a json files' object array to access its variables'

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.