views:

55

answers:

3

Actually, I am doing some labeling. One of my combo box with item[3sec, 5sec, 10sec, 30sec ...] I would like to add a resource key (s, sec) and use it like

Text="3<%$ Resources: myResource, s%>" to get comboBoxItem 3sec,
Text="5<%$ Resources: myResource, s%>" to get comboBoxItem 5sec ...

But I find that the server will treat this as plain text.

I must define each item in seperated resource key pair? please advise.

A: 

You could do it like this (with a DataBind() call somewhere):

Text='<%# "3" + Resources.myResource.s %>'

Edit: You can also do this from code behind. Something like this:

int[] times = new int[]{ 3, 5, 10, 30 };
foreach (int time in times)
{
    string text = time.ToString() + Resources.myResource.s;
    cbo.Items.Add(new ListItem(text, time.ToString()));
}

Edit 2: As per Muhammad's observation the first example doesn't work for this. I've used it for other controls, and I didn't see that for the current case it's not correct. Given this I would fill the control from code behind.

rslite
I have checked, this is giving error..Text='<%# "3" + Resources.myResource.s %>'
Muhammad Akhtar
A: 

You can try creating your own custom expression builder. They are really powerful if you want to achieve what you have asked in your question.

Or, you can always do it using server-side code.

Kirtan
+2  A: 

Consider defining your resource file entry value as follows:

{0}sec

And then

String.Format(Resources.myResource.s, "3")
Ben Griswold
How are you going to write this in the aspx/ascx page?
Kirtan
Perhaps like : `<%# String.Format("3{0}", Resources.myResource.s) %>`. I don't know if Ben's method works, but if it does, would be a pretty cool way. +1
Cerebrus
Ben's method seems not working ...
Jay
I should have been more clear. This would need to be a code-behind operation.
Ben Griswold