Repeater question

  • Thread starter Thread starter SpaceMarine
  • Start date Start date
S

SpaceMarine

hello,

i have an ASPX page where i bind a datasource to a Repeater. i then
render stuff in my <ItemTemplate> like so:

<td>
<%#DataBinder.Eval(Container.DataItem, "FirstName")%>,
<%#DataBinder.Eval(Container.DataItem, "LastName")%>
</td>

....thats cool, unless the above Eval()s are empty -- in which case you
end up w/ a silly-looking "," and no names.

so i want to write a function to evaluate multiple values in the
DataItem at run-time. my question is -- what can i pass into this
function in order to do this? something like this:

<td>
<%= MyFunction(Container) %>
</td>

public function MyFunction(DataItem item)
{
string returnValue = string.empty;

//do some string analysis on the passed-in item. if both names
exist, return them formatted as i like

return returnValue;
}


....the above doesnt seem quote right.

can anyone assist?


thanks!
matt
 
...the above doesnt seem quote right.

The ASP.NET idiosyncratic way of solving this task would probably be:

1. Declare a Literal control within the body of your Repeater markup.

2. Attach a new method to handle the ItemDataBound event of the Repeater.

a) Read data from e.Item.DataItem and do the computations and
comparisons needed to build the string you want to display.

b) Use e.Item.FindControl("myLiteral") to get a reference to the
literal control, cast it, and assign its new Text value.

This might not be the simplest way to solve the task, but I believe this
is how you supposed to do it in ASP.NET :-)
 
....

<%# MyFunction( Container.DataItem )%>

....



public function MyFunction(object item)
{

MyObject mo = item as MyObject;

...

}
 
Back
Top