Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET - Referencing a checkbox in a nested repeater

Posted on 2004-10-21
5
Medium Priority
?
1,012 Views
Last Modified: 2008-02-01
Hi All:

Having trouble getting my code to see the checkbox I am referencing in the nested repeater. The error is:

"Object variable or With block variable not set."

on this line : "For i = 0 To rptRiskNote.Items.Count - 1"

-- repeater --
<asp:repeater id="rptDivision" runat="server">
<ItemTemplate>
      <b>
            <%# DataBinder.Eval(Container.DataItem, "DivisionDesc")%>
      </b>
      <HR>
      <asp:repeater id="rptRiskNote" runat="server" DataSource='<%# RiskNoteDataBind(DataBinder.Eval(Container.DataItem,"DivisionID")) %>'>
            <HeaderTemplate>
                  <ul>
            </HeaderTemplate>
            <ItemTemplate>
                  <LI>
                        <asp:CheckBox id="chkSel" runat="server"></asp:CheckBox>
                        <asp:Label id="lblID" runat="server" Visible="false" Text='<%#DataBinder.Eval(Container.DataItem, "RiskID")%>'>
                        </asp:Label>
                        <%#DataBinder.Eval(Container.DataItem, "Title") & " .."%>
                        </a></span>
                        <br>
            </ItemTemplate>
            <FooterTemplate>
                  </ul>
            </FooterTemplate>
      </asp:repeater><BR />
</ItemTemplate>
<HeaderTemplate>
</HeaderTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:repeater>
----------------

--- CODE ---
Dim strID As String = ""
        Dim i As Integer

        Dim rptRiskNote = CType(rptDivision.FindControl("rptRiskNote"), Repeater)

        For i = 0 To rptRiskNote.Items.Count - 1
            Dim ckb As CheckBox = CType(rptRiskNote.Items(i).FindControl("chkSel"), CheckBox)

            If ckb.Checked Then
                strID += (CType(rptRiskNote.Items(i).FindControl("lblID"), Label)).Text + ","
            End If
        Next
------------
0
Comment
Question by:Mitchell_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 12371809
Are you iterating through the items collection of the first repeater?  That is the only way you can successfully access the nested repeater.  There are (or could be) multiple rptRiskNotes within rptDivision, so you can't just directly access it.
0
 
LVL 33

Expert Comment

by:raterus
ID: 12371820
also, what exactly is this code doing?, are you running this on a postback of a repeater event?
0
 

Author Comment

by:Mitchell_
ID: 12371840
My goal is to iterate through the checkboxes in the 2nd repeater and make a string out of each ID that is checked off.

Do you have any sample code I could use? How would I talk to the 2nd repeater by looping through the 1st?
0
 
LVL 33

Accepted Solution

by:
raterus earned 2000 total points
ID: 12371954
Try this

--
Dim strID As String = ""

For Each ri As RepeaterItem In rptDivision.Items

        Dim rptRiskNote as Repeater = CType(ri.FindControl("rptRiskNote"), Repeater)

        For i as integer = 0 To rptRiskNote.Items.Count - 1
            Dim ckb As CheckBox = CType(rptRiskNote.Items(i).FindControl("chkSel"), CheckBox)

            If ckb.Checked Then
                strID += (CType(rptRiskNote.Items(i).FindControl("lblID"), Label)).Text + ","
            End If
        Next

Next
0
 

Author Comment

by:Mitchell_
ID: 12372903
worked! thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question