Nested Repeater Find Control on Button Click

Joined
Nov 13, 2009
Messages
1
Reaction score
0
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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top