Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Re: conditional formatting in repeater


Message #1 by aarons@u... on Sat, 1 Mar 2003 01:12:11
> I'm sure I'm missing something obvious, but how does one modify 
repeater 
c> ontent based on the values in the RepeaterItem.DataItem?

> For example, let's say that if value x > 4 I want a .gif to appear next 
t> o the content. I've tried something like;

> <%# DataBinder.Eval(Container.DataItem, "x"))%>
<> % if ((int)Container.DataIem["x"] > 4)
.> ...

> I've also tried mucking about with the Repeater.ItemCreated event with 
no 
l> uck and significant confusion.

> Thanks,
A> aron Spitzer
U> . of Washington
D> ept of Biostatistics

Ha! I've answered my own question - thought I'd share with y'all. The 
trick is, in fact, in the ItemCreated event of the Repeater control. The 
RepeaterItemEventArgs passed in contains an Item and this Item contains a 
DataItem. I tried casting this to all sorts of stuff without success 
(MSDN wasn't much help, explaining it as a "data item"). I finally gained 
access to the Item.DataItem by using DataBinder.Eval (duh) - so...

protected void FormatRepeaterItem(object sender, RepeaterItemEventArgs e)
{
   int a1 = (int)DataBinder.Eval(e.Item.DataItem,"FooCount");	
   if(a1 > 4)
   {
      Label lab = new Label();
      lab.Text = "<img src='mygif.gif'>";
      e.Item.Controls.Add(lab);
   )
}

  Return to Index