Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically accessing Data in an ASP.NET 2.0 Repeater
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload