2014年7月13日 星期日

[RESOLVED] How do I update DataPager Text programmatically (in code-behind)?


Hi,


I'm trying to localise a website for multiple languages.  I'm using a DataPager which has "First" and "Last" buttons.


I need to dynamically change this text depending upon the language/culture the user is viewing the site with.


I've tried several different ways of changing the text without success...


Help is appreciated!


This is my datapager:


    PagedControlID="lvEventsSearchResults" PageSize="15">

ShowNextPageButton="False" ShowPreviousPageButton="False" FirstPageText="First" />

ShowNextPageButton="False" ShowPreviousPageButton="False" LastPageText="Last" />


I found some code elsewhere in the forum from PeteNet (http://forums.asp.net/p/1454256/3325616.aspx) for use in the DataPager's PreRender that I converted to VB.net and tried to tweak without success...


My attempt was:


Dim dataPager As DataPager = DirectCast(sender, DataPager)
If dataPager Is Nothing Then
Return
End If

Dim NumericPagerFieldIndex As Integer = 0

Dim count As Integer = dataPager.Controls(NumericPagerFieldIndex).Controls.Count
If TypeOf dataPager.Controls(NumericPagerFieldIndex).Controls(count - 3) Is Button Then
Dim btn As Button = DirectCast(dataPager.Controls(NumericPagerFieldIndex).Controls(count - 3), Button)
btn.Text = "hiya"
End If

Throws no errors...but doesn't work!





Hi rlovetx,


In asp.net Resource files are the best approach to implement multilingual features. Just create multiple resource files, each carryings its language specific labels for button, links and any other stuff. For example you can have Res1.resx for English, Res1.fr.resx
for French and so on. And at run time just set the UI-culture of your thread as,


protected override void InitializeCulture()
{
UICulture = “your culture,like en-US or fr-FR” etc;
base.InitializeCulture();
}

And then map your static labels to use Resource files, like



ShowNextPageButton="False" ShowPreviousPageButton="False" FirstPageText="<>map to Resurce file<> />

ShowNextPageButton="False" ShowPreviousPageButton="False" LastPageText="<>map to Resurce file<>" />


and follow the link for details explanation, http://www.codeproject.com/Articles/334820/Using-Globalization-and-Localization-in-ASP-NET


thanks



Thanks, ijaz.


I don't think that's going to work for me.


I'm using Dot Net Nuke which has already implemented Localization and I have a .resx LocalResourceFile that DNN is reading from.


However, it throws and error if I try to use their resourcekey or the meta:resourcekey attributes on the datapager.


I have everything else on the page working with the DNN Localization (either using resourcekey or looking up values in the code-behind).


I'm just stumped on this datapager text.



Hey--


Never found a good resolution to this.


For future searchers, our solution was simply to use double arrows instead of text (<< and >>).



沒有留言:

張貼留言