WebAIM - Web Accessibility In Mind

E-mail List Archives

RE: ASP.Net repeater controls and labeling


From: Keith Patton
Date: Mar 22, 2004 2:33PM

Hi Lainie,

One solution would be to use a literal control to output the label using
the databind event of the repeater control:

<!-html -->
<asp:Repeater ID="rpt" Runat="server>"
<asp:Literal ID="litFor" Runat="server" />
<asp:TextBox ID="txtBox" Runat="server" />

'' vb.net code behind file

Protected WithEvents rpt As Repeater

Private Sub rpt_DataBind(ByVal s As Object, ByVal e As
repeaterItemEventArgs) Handles rpt.ItemDataBound
Dim objItemType As ListItemType = CType(e.Item.ItemType,

If objItemType = ListItemType.Item Or objItemType ListItemType.AlternatingItem Then
Dim txtBox As TextBox CType(e.Item.FindControl("txtBox"), TextBox)
Dim litFor As Literal CType(e.Item.FindControl("litFor "), Literal)
litFor.Text = "<label for=""" & txtBox.ClientID
& """>LABEL NAME</label>"
End If

End Sub

Note that in a normal ASP.NET page it's very easy to use label for with
a server control when you aren't troubled by binding, by doing the
following for example

<label for="<%= txtBox.ClientID %>">Search Text</label>
<input type="text" id="txtBox" Runat="server" />

'' vb code behind file
Protected WithEvents txtBox As HtmlInputControl

Hope that helps,

Keith Patton

Technical Director
Ethical Media
-----Original Message-----
From: Martin, Lainie [mailto: <EMAIL REMOVED> ]
Sent: 22 March 2004 18:49
Subject: ASP.Net repeater controls and labeling

Has anyone found a good way to label repeater controls in ASP.Net?

I have a header row with "label for" tags around the corresponding
column header.
Then below that I've got the data repeating for 15 rows down.

But because of the nature of repeaters, the id for each corresponding
text box dynam