Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate?

Reply
Thread Tools

can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate?

 
 
Bennett Haselton
Guest
Posts: n/a
 
      09-24-2004
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
 
Reply With Quote
 
 
 
 
Joe Fallon
Guest
Posts: n/a
 
      09-24-2004
I use the ItemDatBound in my grids to manipulate stuff.
I assume you can do the same for a Repeater.
===========================================
Sample code:
===========================================
Private Sub dg1_ItemDataBound(ByVal sender As System.Object, ByVal e As
DataGridItemEventArgs) Handles dg1.ItemDataBound
If e.Item.ItemType = ListItemType.Header Then
'do something to the header
End If

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
'need to take paging into account!
Dim mIndex As Integer = CType(sender, DataGrid).PageSize *
CType(sender, DataGrid).CurrentPageIndex + e.Item.ItemIndex

'set Status hyperlink
Dim oHylStatus As HyperLink = CType(e.Item.FindControl("hylStatus"),
HyperLink)
If mCollection(mIndex).statustext = "None" Then
oHylStatus.NavigateUrl = ""
Else
oHylStatus.NavigateUrl = "javascript:..;"
End If
oHylStatus.Text = mCollection(mIndex).statustext

If mCanAmend=True Then
Dim oBtnAmend As ImageButton = CType(e.Item.FindControl("btnAmend"),
ImageButton)
If mCollection(mIndex).status = "XYZ" Then
oBtnAmend.Visible = True
Else
oBtnAmend.Visible = False
End If
End If

End If
End Sub

--
Joe Fallon




"Bennett Haselton" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a controls ID property inside a repeater controls ItemTemplate the value of the ItemIndex? Andy B ASP .Net 1 11-15-2008 07:17 PM
Using a Custom Server Control inside an ItemTemplate in DataList Charlie@CBFC ASP .Net 2 05-18-2006 04:25 PM
Using Custom Server Control inside ItemTemplate in DataList Charlie@CBFC ASP .Net 0 05-17-2006 04:17 PM
adding table inside itemtemplate Edge ASP .Net 6 01-12-2006 09:15 AM
Modify Datalist standard itemtemplate output Martman ASP .Net 5 12-05-2004 01:07 PM



Advertisments