Hi Chad,
Teemu has a great answer. You can also use the repeater's ItemDataBound
event. This event fires for each row in the repeater (one by one).
Here's a small sample that demonstrates a little of what you can do in this
event.
*** Here is my repeater control
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<input id=one name=one type=text runat=server value=
'<%# Container.DataItem("au_id")%>'>
<br>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
*** Here is my code
Dim Counter As Integer = 0
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Bind()
End If
End Sub
Private Sub Bind()
Dim Qry1 As System.Data.SqlClient.SqlDataReader
Dim connectionString As String = "server='localhost';
trusted_connection=true; Database='pubs'"
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)
Dim queryString As String = "SELECT au_id, au_lname, au_fname FROM
authors"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Qry1 =
sqlCommand.ExecuteReader(System.Data.CommandBehavi or.CloseConnection)
Repeater1.DataSource = Qry1
Repeater1.DataBind()
Qry1.Close()
sqlCommand.Dispose()
sqlConnection.Close()
sqlConnection.Dispose()
End Sub
Private Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
Repeater1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
If e.Item.DataItem("au_lname") = "Green" Then
Dim l As LinkButton = New LinkButton
l.Text = e.Item.DataItem("au_lname")
l.ForeColor = System.Drawing.Color.Green()
e.Item.Controls.Add(l)
End If
Counter += 1
End If
If e.Item.ItemType = ListItemType.Footer Then
Dim t As TextBox = New TextBox
t.Text = Counter.ToString & " People"
t.ForeColor = System.Drawing.Color.Green()
t.ReadOnly = True
e.Item.Controls.Add(t)
End If
End Sub
I hope this helps.
Thank you, Mike
Microsoft, ASP.NET Support Professional
Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.
This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
From: "Chad THomas" <ct*****@echosat.com>
Subject: Dynamic Links
Date: Wed, 17 Dec 2003 14:38:36 -0500
Lines: 10
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#2**************@TK2MSFTNGP11.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 12.158.50.129
Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA05.phx.gbl!TK2MSFTNGP08
..phx.gbl!TK2MSFTNGP11.phx.gbl Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:196986
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
I have a data repeater controll on a page. in each row that is displayed,
I would like to have an action column that has differnet links shown
depending on certain criteria from the database. In traditional asp you could check
the value as you looped through the recordset, but in asp.net I am not
sure how to do it if you are binding to a control.
Thanks,
Chad