How to do this? Need advice.

  • Thread starter Thread starter Shapper
  • Start date Start date
S

Shapper

Hello,

I have a problem: Inside the Item Template of an ASP:Repeater I need to
display a link.

The link url value is given by:
<%# DataBinder.Eval(Container.DataItem, "link") %>

The link text changes according to the culture of my web site:
"pt-PT" - Lêr Mais
"en-GB" - Read More
....

I tried to use a <a> tag where the text is taken from a public variable.
OR
To use an ASP: Hiperlink.

Anyway, I am having problems in both and I am not even sure if there are
the best options

I also have a session variable, session("culture"), where current
culture is available.

Can someone advice me on this?

I know this is simple but I am having problems with it.

Thank You,
Miguel
 
I'm not sure what you're really trying to do, but it soulds like you have
some complex logic that determines what appears in your data bound template.
When I have this situation I factor out that code into a method in my page:

string GetString(object row)
{
// ...
}

And then call this from my data binding code:

<ItemTemplate>
<a href='...'><%# GetString(Container.DataItem)%></a>
</ItemTemplate>

So then in your method, you do your logic. The row parameter is the row from
your data source, so you can access andy column via DataBinder.Eval:

string GetString(object row)
{
int val1 = (int)DataBinder.Eval(row, "ColumnOne");
string val2 = (string)DataBinder.Eval(row, "ColumnTwo");
// ...
return "This is the string that will be in the data bound template";
}

And just return a dynamically created string to fill into the data bound
template.

-Brock
DevelopMentor
http://staff.develop.com/ballen
 

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

Back
Top