<p>This is an ASP.Net 2.0 web app. The Item template looks like this, for reference:</p>

<pre><code>&lt;ItemTemplate&gt;
  &lt;tr&gt;
    &lt;td class="class1" align=center&gt;&lt;a href='url'&gt;&lt;img src="img.gif"&gt;&lt;/a&gt;&lt;/td&gt;
    &lt;td class="class1"&gt;&lt;%# DataBinder.Eval(Container.DataItem,"field1") %&gt;&lt;/td&gt;
    &lt;td class="class1"&gt;&lt;%# DataBinder.Eval(Container.DataItem,"field2") %&gt;&lt;/td&gt;
    &lt;td class="class1"&gt;&lt;%# DataBinder.Eval(Container.DataItem,"field3") %&gt;&lt;/td&gt;
    &lt;td class="class1"&gt;&lt;%# DataBinder.Eval(Container.DataItem,"field4") %&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/ItemTemplate&gt;
</code></pre>

<p>Using this in codebehind:</p>

<pre><code>foreach (RepeaterItem item in rptrFollowupSummary.Items)
{
    string val = ((DataBoundLiteralControl)item.Controls[0]).Text;
    Trace.Write(val);
}
</code></pre>

<p>I produce this:</p>

<pre><code>&lt;tr&gt;
  &lt;td class="class1" align=center&gt;&lt;a href='url'&gt;&lt;img src="img.gif"&gt;&lt;/a&gt;&lt;/td&gt;
  &lt;td class="class1"&gt;23&lt;/td&gt;
  &lt;td class="class1"&gt;1/1/2000&lt;/td&gt;
  &lt;td class="class1"&gt;-2&lt;/td&gt;
  &lt;td class="class1"&gt;11&lt;/td&gt;
&lt;/tr&gt;
</code></pre>

<p>What I need is the data from Field1 and Field4</p>

<p>I can't seem to get at the data the way I would in say a DataList or a GridView, and I can't seem to come up with anything else on Google or quickly leverage this one to do what I want.  The only way I can see to get at the data is going to be using a regex to go and get it (Because a man takes what he wants. He takes it all. And I'm a man, aren't I? Aren't I?).  </p>

<p>Am I on the right track (not looking for the specific regex to do this; forging that might be a followup question ;) ), or am I missing something?</p>

<hr>

<p>The Repeater in this case is set in stone so I can't switch to something more elegant.  Once upon a time I did something similar to what Alison Zhou suggested using DataLists, but it's been some time (2+ years) and I just completely forgot about doing it this way.  Yeesh, talk about overlooking something obvious. . .</p>

<p>So I did as Alison suggested and it works fine.  I don't think the viewstate is an issue here, even though this repeater can get dozens of rows.  I can't really speak to the question if doing it that way versus using the  instead (but that seems like a fine solution to me otherwise).  Obviously the latter is less of a viewstate footprint, but I'm not experienced enough to say when one approach might be preferrable to another without an extreme example in front of me.  Alison, one question: why literals and not labels?</p>

<p>Euro Micelli, I was trying to avoid a return trip to the database.  Since I'm still a little green relative to the rest of the development world, I admit I don't necessarily have a good grasp of how many database trips is "just right".  There wouldn't be a performance issue here (I know the app's load enough to know this), but I suppose I was trying to avoid it out of habit, since my boss tends to emphasize fewer trips where possible.</p>

[{'answer_id': 54738, 'author': 'ern', 'author_id': 5609, 'author_profile': 'https://Stackoverflow.com/users/5609', 'pm_score': 2, 'selected': False, 'text': '<p>Since you are working with tabular data, I\'d recommend using the GridView control. Then you\'ll be able to access individual cells.</p>\n\n<p>Otherwise, you can set the td\'s for Field1 and Field4 to <code>runat="server"</code> and give them ID\'s. Then in the codebehind, access the <code>InnerText</code> property for each td.</p>\n'}, {'answer_id': 54743, 'author': 'Dillie-O', 'author_id': 71, 'author_profile': 'https://Stackoverflow.com/users/71', 'pm_score': 0, 'selected': False, 'text': '<p>If you can afford a smidge more overhead in the generation, go for DataList and use the DataKeys property, which will save the data fields you need.</p>\n\n<p>You could also use labels in each of your table cells and be able to reference items with e.Item.FindControl("LabelID").</p>\n'}, {'answer_id': 54745, 'author': 'NakedBrunch', 'author_id': 3742, 'author_profile': 'https://Stackoverflow.com/users/3742', 'pm_score': 4, 'selected': True, 'text': '<p>Off the top of my head, you can try something like this:</p>\n\n<pre><code>&lt;ItemTemplate&gt;\n  &lt;tr&gt;\n    &lt;td "class1"&gt;&lt;asp:Literal ID="litField1" runat="server" Text=\'&lt;%# Bind("Field1") %&gt;\'/&gt;&lt;/td&gt;\n    &lt;td "class1"&gt;&lt;asp:Literal ID="litField2" runat="server" Text=\'&lt;%# Bind("Field2") %&gt;\'/&gt;&lt;/td&gt;\n    &lt;td "class1"&gt;&lt;asp:Literal ID="litField3" runat="server" Text=\'&lt;%# Bind("Field3") %&gt;\'/&gt;&lt;/td&gt;\n    &lt;td "class1"&gt;&lt;asp:Literal ID="litField4" runat="server" Text=\'&lt;%# Bind("Field4") %&gt;\'/&gt;&lt;/td&gt;\n  &lt;/tr&gt;\n&lt;/ItemTemplate&gt;\n</code></pre>\n\n<p>Then, in your code behind, you can access each Literal control as follows:</p>\n\n<pre><code>foreach (RepeaterItem item in rptrFollowupSummary.Items)\n{   \n    Literal lit1 = (Literal)item.FindControl("litField1");\n    string value1 = lit1.Text;\n    Literal lit4 = (Literal)item.FindControl("litField4");\n    string value4 = lit4.Text;\n}\n</code></pre>\n\n<p>This will add to your ViewState but it makes it easy to find your controls.</p>\n'}, {'answer_id': 54805, 'author': 'Euro Micelli', 'author_id': 2230, 'author_profile': 'https://Stackoverflow.com/users/2230', 'pm_score': 0, 'selected': False, 'text': '<p>The &lt;%#DataBinder.Eval(...) %&gt; mechanism is not Data Binding in a "strict" sense. It is a one-way technique to put text in specific places in the template.</p>\n\n<p>If you need to get the data back out, you have to either:</p>\n\n<ol>\n<li>Get it from your source data</li>\n<li>Populate the repeater with a different mechanism</li>\n</ol>\n\n<p>Note that the Repeater doesn\'t save the DataSource between postbacks, You can\'t just ask it to give you the data later.</p>\n\n<p>The first method is usually easier to work with. Don\'t assume that it\'s too expensive to reacquire your data from the source, unless you prove it to yourself by measuring; it\'s usually pretty fast. The biggest problem with this technique is if the source data can change between calls.</p>\n\n<p>For the second method, a common technique is to use a Literal control. See <a href="https://stackoverflow.com/questions/54708/programmatically-accessing-data-in-an-aspnet-20-repeater#54745">Alison Zhou</a>\'s post for an example of how to do it. I usually personally prefer to fill the Literal controls inside of the OnItemDataBound instead</p>\n'}, {'answer_id': 54935, 'author': 'Euro Micelli', 'author_id': 2230, 'author_profile': 'https://Stackoverflow.com/users/2230', 'pm_score': 0, 'selected': False, 'text': '<p><a href="https://stackoverflow.com/questions/54708/programmatically-accessing-data-in-an-aspnet-20-repeater#54860">@peacedog</a>:  </p>\n\n<p>Correct; Alison\'s method is perfectly acceptable.</p>\n\n<p>The trick with the database roundtrips: they are not free, obviously, but web servers tend to be very "close" (fast, low-latency connection) to the database, while your users are probably "far" (slow, high-latency connection).</p>\n\n<p>Because of that, sending data to/from the browser via cookies, ViewState, hidden fields or any other method can actually be "worse" than reading it again from your database. There are also security implications to keep in mind (Can an "evil" user fake the data coming back from the browser? Would it matter if they do?).</p>\n\n<p>But quite often it doesn\'t make any difference in performance. That\'s why you should do what works more naturally for your particular problem and worry about it only <strong>if</strong> performance starts to be a real-world issue.</p>\n\n<p>Good luck!</p>\n'}]
['https://Stackoverflow.com/questions/54708', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1734/']