B
Bennett Haselton
If I have this code for repeater, it gives a compilation error saying
"The type or namespace name 'MyValue2' could not be found":
<asp:Repeater id="MyList" runat="server">
<ItemTemplate>
<%#Container.DataItem%><br>
<% MyValue2.Text = "ghi"; %>
<asp:TextBox ID="MyValue2" Runat="server"/>
<br>
</ItemTemplate>
</asp:Repeater>
Presumably that's because the MyValue2 control is inside an
ItemTemplate that gets repeated multiple times, so each instance of
MyValue2 gets a unique ID when the page is actually rendered, and the
C# code can't find the "MyValue2" because they were given a series of
unique names instead. (In fact I can even see their IDs in the source
code of the rendered page -- MyList__ctl0_MyValue2,
MyList__ctl1_MyValue2, etc.)
So, is there a way to have inline code inside the ItemTemplate that
can modify a control that's also repeated inside the template?
I have four ASP.Net books and I can't find any examples in any of them
showing how to do this... Maybe it can't be done?
-Bennett
"The type or namespace name 'MyValue2' could not be found":
<asp:Repeater id="MyList" runat="server">
<ItemTemplate>
<%#Container.DataItem%><br>
<% MyValue2.Text = "ghi"; %>
<asp:TextBox ID="MyValue2" Runat="server"/>
<br>
</ItemTemplate>
</asp:Repeater>
Presumably that's because the MyValue2 control is inside an
ItemTemplate that gets repeated multiple times, so each instance of
MyValue2 gets a unique ID when the page is actually rendered, and the
C# code can't find the "MyValue2" because they were given a series of
unique names instead. (In fact I can even see their IDs in the source
code of the rendered page -- MyList__ctl0_MyValue2,
MyList__ctl1_MyValue2, etc.)
So, is there a way to have inline code inside the ItemTemplate that
can modify a control that's also repeated inside the template?
I have four ASP.Net books and I can't find any examples in any of them
showing how to do this... Maybe it can't be done?
-Bennett