Nested Repeater Find Control on Button Click

Discussion in '.NET' started by stubsz, Nov 13, 2009.

  1. stubsz

    stubsz

    Joined:
    Nov 13, 2009
    Messages:
    1
    I am really stuck on this one!

    I am pretty new to .NET so I'm creating a website as a project so that I can improve my knowledge. I have recently implemented a nested repeater on my page. The outer repeater brings back "headings" and the inner nested repeater brings back items related to the headings. Basically, I am using a nested repeater so that I can group my items e.g.

    Heading 1
    Item 1
    Item 2
    Item 3

    Heading 2
    Item 4
    Item 5
    Item 6

    My code for the repeater looks like this:

    -------------------------------------------------

    <asp:Repeater ID="rptMenu" runat="server" DataSourceID="dsrc1">

    <ItemTemplate>

    <p><strong><asp:Label ID="lblSection" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"usermenu_type") %>'></asp:Label></strong></p>

    <asp:Repeater runat="server" ID="rptChildMenu" DataSourceID="dsrc2">

    <HeaderTemplate>

    <table>

    </HeaderTemplate>

    <ItemTemplate>

    <tr>

    <td><asp:HiddenField ID="hdn_fieldreference" runat="server" value='<%#DataBinder.Eval(Container.DataItem,"usermenu_field_reference") %>' /></td>

    <td><asp:TextBox ID="tbox_menu" CssClass="inputFields" style="width: 200px;" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"usermenu_dishname") %>'></asp:TextBox></td>

    <td>£&nbsp;<asp:TextBox ID="tbox_price" CssClass="inputFields" style="width: 50px;" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"usermenu_price") %>'></asp:TextBox></td>

    </tr>

    </ItemTemplate>

    <FooterTemplate>

    </table>

    </FooterTemplate>

    </asp:Repeater>

    <asp:SqlDataSource ID="dsrc2" runat="server" ConnectionString="<%$ ConnectionStrings:connString %>" SelectCommand="SELECT usermenu_dishname, usermenu_price, usermenu_type, usermenu_field_reference FROM tblUserMenu WHERE usermenu_user_reference = @Reference and usermenu_type = @Section">

    <SelectParameters>

    <asp:ControlParameter ControlID="lblSection" Name="Section" />

    <asp:SessionParameter Name="Reference" SessionField="Reference" />

    </SelectParameters>

    </asp:SqlDataSource>

    </ItemTemplate>

    </asp:Repeater>

    <asp:Button ID="btn1" runat="server" Text="Button" />

    <asp:SqlDataSource ID="dsrc1" runat="server" ConnectionString="<%$ ConnectionStrings:connString %>" SelectCommand="SELECT DISTINCT usermenu_type FROM tblUserMenu WHERE (usermenu_user_reference = @Reference)">

    <SelectParameters>

    <asp:SessionParameter Name="Reference" SessionField="Reference" />

    </SelectParameters>

    </asp:SqlDataSource>

    -------------------------------------------------


    I have read some posts that relate to the outer repeater's ItemDataBound method and you have to bind the inner repeater? If I am using a SQLDataSource and passing in the SQL, then what would I pass in as the datasource? I am passing in the sql through the asp data source block as I need to be able to pass in the label's name so that I can get the items back based upon this so that I can group them (WHERE (usermenu_user_reference = @Reference))

    What I have been attempting to do is to have a button, which is outside of the repeater, and when clicked, it will update values in the database. Problem is, I cannot get the FindControl method to work as I keep getting an "object reference not set" error in the button's click method. How do I access the textboxes in the nested repeater in this method? Can it be done?

    Hopefully someone will have an idea of how this newbie can get this to work.

    Any help will be appreciated.

    BTW - I am using VB.

    Cheers!
    stubsz, Nov 13, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    830
    Purvi T
    Oct 19, 2004
  2. chris.reed@digus.com

    Repeater control with nested repeater

    chris.reed@digus.com, Feb 11, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    853
    chris.reed@digus.com
    Feb 11, 2005
  3. Amy
    Replies:
    0
    Views:
    976
  4. AlecL
    Replies:
    3
    Views:
    1,204
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Apr 11, 2007
  5. Brian Miller
    Replies:
    6
    Views:
    689
    Brian Miller
    Nov 18, 2004
Loading...

Share This Page