Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
By following <%$ Resources:Class, ResourceKey %> I want to show the value of "ResourceKey" in repeater or gridview.
My class name is "Notification" and KeyName is "MyKey". I have stored the key name in database and i am able to get the key name from database. But not able to show the value of key in label control in repeater. I followed the syntax <%$ Resources:Class, ResourceKey %>

I tried <asp:Label ID="Label1" runat="server" Text='<%$ Resources:Notification,Eval("MyKey") %>' /> but it doesn't work.
Please help me to resolve this issue.
Posted
Updated 30-Nov-14 21:39pm
v2

1 solution

You could use
ItemDataBound event[^] to set controls value depending on your data.

I've mostly used it to write Yes/No, Da/Ne, Ja/Nein depending on bool value from the database, date formatting and similar, but you can set value to any control (including labels)

C#
Label lbl = (Label)e.Item.FindControl("lblWhatever")
lbl.Text = Resources.MyKey //(or however that goes server side, writing without references)


If this helps please take time to accept the solution. Thank you.
 
Share this answer
 
Comments
xpertzgurtej 13-May-15 8:49am    
.
Sinisa Hajnal 13-May-15 9:30am    
Lets try this again:
- your problem has nothing to do with the database...you cannot use Resource:key notation for something that is not in your resources file. You have to write your own.

Therefore, get all the strings for the given page on page load and store them in the session. On item data bound event of the repeater set the controls based on values from your session.

If you really want to, you could get the resources from the database for each control, but that would be slow as you would make a round trip to the database for each control.


Now, please explain the above block of SQL. Is there a question there? Problem? If so, please move it (Improve question link) into the question, don't post big blocks of code in the comments. Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900