Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing data within a Repeater Control

Status
Not open for further replies.

fifer57

Programmer
Jun 28, 2003
1
0
0
US
I am using a Repeater control to display a list of article titles contained in a database. Some of these have a URL link to the full article. In the case where there is a URL I want to make the title a link to that URL.
...

<asp:Repeater ID=&quot;dgArticlesRep&quot; Runat=&quot;server&quot;>
<HeaderTemplate>
<ol>
</HeaderTemplate>
<ItemTemplate>
<li><a href=&quot;<%# DataBinder.EvalContainer.DataItem, &quot;URL&quot;) %>&quot;><%# DataBinder.Eval(Container.DataItem, &quot;title&quot;) %></a></li>
</ItemTemplate>
<FooterTemplate>
</ol>
</FooterTemplate>
</asp:Repeater>

...

Retrieving the data and binding it to the control is no problem but how after being bound do I pick out individual bits of data from the control? I need to access the URL field to determine if the title should be a link or not.

Any help on this would be greatly appreciated.
 
Hi Fifer57

I have a Repeater with textBox inside it, and i need to access the values of this textbox, it is similer to your problem, I tried to name the textbox with a non constant ID Like in the following:

<asp:Repeater id=&quot;repContact&quot; runat=&quot;server&quot;>
<ItemTemplate>
<asp:textbox name='txtContactInfo_&quot;<%# Container.DataItem(&quot;CategoryID&quot;)%>&quot;' runat=&quot;server&quot; />
</ItemTemplate> </asp:Repeater>

Code behind:
Dim newtb As TextBox = new TextBox()
strSQL = &quot;Select CategoryID &quot; _
& &quot;From ContactInfo &quot; _
& &quot;Where CategoryID = &quot; & iID

myCommand = New OleDbCommand (strSQL, objConn)
dataReader = myCommand.ExecuteReader()

Do While dataReader.Read()
newtextboxname = (&quot;CategoryID&quot;)
newtb.ID = &quot;txtContactInfo_&quot; + newtextboxname

Dim myComm As OleDbCommand = New OleDbCommand (strSQL,dbConn)
strSQL = &quot;Update ContactInfo &quot; _
& &quot;Set ContactInfo = '&quot; & newtb.Text.Trim() & &quot;' &quot; _
& &quot;Where CategoryID = &quot; & iID

myComm.CommandText = strSQL

myComm.ExecuteNonQuery()

myComm.Cancel()
Loop
dataReader.Close()

this code is not working, and i wonder if the problem was in defining the textbox ID.

did you find a solution for your problem yet?

Thanks for helping
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top