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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:24:08+00:00 2026-06-12T23:24:08+00:00

I currently have a datareader as my datasource which is bound to a repeater.

  • 0

I currently have a datareader as my datasource which is bound to a repeater. as seen here:

Try
            myConnection.Open()
            sqlCommand = New SqlCommand(sqlText, myConnection)
            dr = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection)
            cropPlanRepeater.DataSource = dr
            cropPlanRepeater.DataBind()
 Catch ex As Exception

 End Try

This launches the databound event, like so:

Public Sub CropPlanRepeater_ItemDataBound(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles cropPlanRepeater.ItemDataBound

    Dim rptI As RepeaterItem = e.Item
    Dim AmttoSell = TryCast(rptI.FindControl("amtToSell"), Label)
    AmttoSell.Text = AmttoSell
End Sub

For some reason, this findcontrol method, keeps returning “null” or “nothing” I’ve tried to see if there is a flaw in my heirarchy of controls and whatnot, but I can’t find anything.

here’s the HTML for a look at how it works:

<asp:Repeater ID="cropPlanRepeater" runat="server" Visible="false">
            <HeaderTemplate>
                <tr align="center" class="top-rpt-head">
                    <th scope="col">
                        Crop
                    </th>
                    <th scope="col">
                        Production
                    </th>
                    <th scope="col">
                        Amount to Sell
                    </th>
                    <th scope="col">
                        Breakeven
                    </th>
                    <th scope="col">
                        Target Price
                    </th>
                    <th scope="col">
                        Target Revenue
                    </th>
                    <th scope="col">
                        Feed Value
                    </th>
                    <th scope="col">
                        Other Income
                    </th>
                    <th scope="col">
                        Expenses
                    </th>
                    <th scope="col">
                        Profit
                    </th>
                </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr align="center">
                    <td>
                    <!--- this needs to be fixed- incorrect methodology(should be done in the codebehind)----->
                        <%# (DataBinder.Eval(Container.DataItem, "Crop_Name"))%>
                    </td>
                    <td>
                    <!--- this needs to be fixed- incorrect methodology(should be done in the codebehind)----->
                        <%# (DataBinder.Eval(Container.DataItem, "Acres_D") * DataBinder.Eval(Container.DataItem, "Yield_D") + DataBinder.Eval(Container.DataItem, "Acres_I") * DataBinder.Eval(Container.DataItem, "Yield_I"))%>
                    </td>
                    <td>

                    </td>
                 </tr>
                    <asp:label runat="server" ID="AmtToSell"></asp:Label>

                    <asp:Literal runat="server" ID="Yield_I" Text='<%#Eval("Yield_I") %>' Visible="false" />
                    <asp:Literal runat="server" ID="Yield_D" Text='<%#Eval("Yield_D") %>' Visible="false" />
                    <asp:Literal runat="server" ID="Acres_I" Text='<%#Eval("Acres_I") %>' Visible="false" />
                    <asp:Literal runat="server" ID="Acres_D" Text='<%#Eval("Acres_D") %>' Visible="false" />
                    <asp:Literal runat="server" ID="Storage" Text='<%#Eval("Storage") %>' Visible="false" />
                    <asp:Literal runat="server" ID="Fed" Text='<%#Eval("Fed") %>' Visible="false" />
                    <asp:Literal runat="server" ID="Bartered" Text='<%#Eval("Bartered") %>' Visible="false" />
                    <asp:Literal runat="server" ID="Profit_I" Text='<%#Eval("ProfAcre_I") %>' Visible="false" />
                    <asp:literal runat="server" ID="Profit_D" Text='<%#Eval("ProfAcre_D") %>' Visible="false" />         
            </ItemTemplate>
        </asp:Repeater>

I’ve tried putting the label inside and outside of the the tables, and the to no avail. I’m not sure if there’s an issue with my HTML or the codebehind. I need to manipulate that label “amttosell” with a calculation in the codebehind. (I’d do something like amttosell.text = some calculation from data acquired from the database/posted on the hidden labels above

Any help would be GREATLY appreciate.

  • 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-06-12T23:24:09+00:00Added an answer on June 12, 2026 at 11:24 pm

    The CropPlanRepeater_ItemDataBound method handles the header, footer, and the items. For the code you have, you need to wrap it in an if block checking that the item type is Item or AlternateItem.

    Public Sub CropPlanRepeater_ItemDataBound(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles cropPlanRepeater.ItemDataBound
    
    Dim rptI As RepeaterItem = e.Item
    
    if rptI.ItemType = ListItemType.Item OR rptI.ItemType = ListItemType.AlternatingItem then
        Dim AmttoSell = TryCast(rptI.FindControl("amtToSell"), Label)
        AmttoSell.Text = AmttoSell
    
    end if
    End Sub
    

    See http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx#Y200

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

Sidebar

Related Questions

I currently have a button when clicked it should open up a new window
I currently have a table of concentrations, which are linked to a table of
currently I have a web which loads excel spreadsheet data into SQL database. When
Here is my code: OdbcConnection conn = new OdbcConnection(Driver={Microsoft Text Driver (*.txt; *.csv)};DSN=scrapped.csv); conn.Open();
I have an ASP.NET data repeater. This is currently set to a data source
Currently have a drop down menu that is activated on a hover (from display:none
Currently have password protection on my main and sub directories, however I'd like to
I currently have a XSLT 2.0 Stylesheet that I am trying to remove empty
I currently have one project that currently contains multiple packages. These packages make up
I currently have 4 tables. Product, Category, SubCategory, ProductSubCategory. Category has a OneToMany SubCategory

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.