Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

user control question

i have a user control with a repeater. i need to pass some info to the repeater which is not in a database. how do i accomplish this?

i have this in my ascx...

<table>
    <asp:Repeater id="SponsorRepeater" runat="server">
        <ItemTemplate>
            <tr>
                <td><%# DataBinder.Eval(Container.DataItem, "Text") %></td>
            </tr>
        </ItemTemplate>
    </asp:Repeater>
</table>

say i have a property which holds text color and that value is not stored in a database. how do i use that value in the repeater?

thanks.

mark
Wednesday, April 13, 2005

The DataSource of the Repeater doesn't have come from a database, so you could bind to some other sort of list if you had one, or if you had a DataSet you could add your own column containing the colours.

If you need to do something more complicated than a DataBinder.Eval, then you might need to attach to the ItemDataBound event of the Repeater. That way, your delegate gets called for each DataItem in the DataSource, and you can do whatever custom processing you need to do. If you were to put server controls inside the ItemTemplate, you could access them and set their properties inside the delegate.

Thom Lawrence
Wednesday, April 13, 2005

Sorry, I'm not exactly sure of your task, so I _guess_ I had somewhat similar problem. Anyway, hope the following code might be of use.

-----------------------------------------------------------

In control code behind:

protected string FormatMyObject(MyObject obj, string textColor)
{
    // do the formating
    ...
    return formattedOutput;
}


In control ascx file, inside repeater template:

<%# FormatMyObject((MyObject)(Container.DataItem), "#006600")%>

DK
Wednesday, April 13, 2005

*  Recent Topics

*  Fog Creek Home