Click here to Skip to main content
13,042,819 members (74,512 online)
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 1 Jan 2009

The Localizable Dropdown for ASP.NET 2.0

, 1 Jan 2009
Rate this:
Please Sign up or sign in to vote.
Simple way of binding dropdown control to resource files


The code shows a simple way of binding ListItem based controls such as dropdown to a resource file. 


The idea is to store data in XML format instead of name value collection and bind it to .NET controls using XMLDataSource object.  

Using the Code  

I've added a string resource "MyCountryList" that contains XML data for dropdown control.  


  <country text="Pakistan" value="PK"/>
  <country text="Iran" value="IR"/>
  <country text="Afghanistan" value="AF"/>

  <country text="Pakistan-Spanish" value="PK"/>
  <country text="Iran-Spanish" value="IR"/>
  <country text="Afghanistan-Spanish" value="AF"/>


<form id="form1" runat="server">
        <asp:HyperLink ID="HyperLink1" runat="server" 

        <asp:HyperLink ID="HyperLink2" runat="server" 

		NavigateUrl="~/Default.aspx?lang=eng">Eng</asp:HyperLink><br />
        <br />
        <asp:Localize ID="Localize1" runat="server" 

		Text="<%$ Resources:Resource, Greeting%>"></asp:Localize>
        <br />
        <asp:XmlDataSource ID="XmlDataSource1" runat="server"></asp:XmlDataSource>
        <asp:DropDownList ID="DropDownList1" runat="server" >


protected void Page_Load(object sender, EventArgs e)
        // loading xml from resource file into xmldatasource object
        XmlDataSource1.Data = Resources.Resource.MyCountryList;
        XmlDataSource1.EnableCaching = false;

        DropDownList1.DataSourceID = "XmlDataSource1";
        DropDownList1.DataTextField = "text";
        DropDownList1.DataValueField = "value";
   //The setting up the culture
    protected override void InitializeCulture()
        string lang = "en-US";
        if (Request.QueryString["lang"] != null)
            switch (Request.QueryString["lang"])
                case "esp":
                    lang = "es-MX";
                case "eng":
                    lang = "en-US";
        System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(lang);
        System.Threading.Thread.CurrentThread.CurrentCulture = ci;
        System.Threading.Thread.CurrentThread.CurrentUICulture = ci;

The lines in italics show the 2 ways to bind to resource files. You can also download the source code attached to this article.


  • 1st January, 2009: Initial post


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


About the Author

Shahid Syed
Software Developer (Senior) Mobile Complete Inc. (DeviceAnywhere)
Pakistan Pakistan
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralProblems with Japanese Pin
NickShelomanov11-Jan-09 22:49
memberNickShelomanov11-Jan-09 22:49 
GeneralBest Localization Plug-in for Visual Studio. Pin
Alexander Nesterenko2-Jan-09 1:34
memberAlexander Nesterenko2-Jan-09 1:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 1 Jan 2009
Article Copyright 2009 by Shahid Syed
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid