Repeater question

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
 
J

Joern Schou-Rode

...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 :)
 
G

gerry

....

<%# MyFunction( Container.DataItem )%>

....



public function MyFunction(object item)
{

MyObject mo = item as MyObject;

...

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top