Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I've some queries that is that possible to create Country's states,cities as a dll sothat we can reference it and use in our project.If it is so Please reply me How to do that.
Posted

Hi,
You can create a country droppdown like this,
[ToolboxData("<{0}:CountryDropDownList runat=server></{0}:CountryDropDownList>")]
    public class CountryDropDownList : DropDownList
    {
        public override void DataBind()
        {
            SortedList slCountry = new SortedList();
            string Key = "";
            string Value = "";

            if (UseFirstItem)
            {
                slCountry.Add(FirstItemText, FirstItemValue);
            }

            foreach (CultureInfo info in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
            {
                RegionInfo info2 = new RegionInfo(info.LCID);
                if (!slCountry.Contains(info2.EnglishName))
                {
                    Value = info2.TwoLetterISORegionName;
                    Key = info2.EnglishName;
                    slCountry.Add(Key, Value);
                }
            }
            base.DataSource = slCountry;
            base.DataTextField = "Key";
            base.DataValueField = "Value";
            base.DataBind();

            if (UseFirstItem)
            {
                base.SelectedIndex = base.Items.IndexOf(base.Items.FindByValue(FirstItemValue));
            }
        }

        private string _firstItemText = "Select Country";
        public string FirstItemText
        {
            get { return _firstItemText; }
            set { _firstItemText = value; }
        }

        private string _firstItemValue = "-1";
        public string FirstItemValue
        {
            get { return this._firstItemValue; }
            set { this._firstItemValue = value; }
        }

        private bool _useFirtItem = false;
        public bool UseFirstItem
        {
            get { return this._useFirtItem; }
            set { this._useFirtItem = value; }
        }
    }


You can download this as project(Imgalib.Utility)from here[^] and use as a dll.
Hope this will help.
 
Share this answer
 
Create a data class as you would normally do in a class library assembly. Make the type and members you need to access from other assemblies public, or internal (all other being private, protected internal or internal).

Add your library assembly to the references of the using assembly. You won't have any barriers between assemblies; use the types and their members as you usually do. Name spaces can be the same or different; it's just the matter of convenience; but don't forget to qualify type names properly.

Avoid hard-coding data in your assembly code. Always prefer reading data from persistent source of data, such as file or data base. Alternatively, use resources embedded in your assembly. Do not hard-code data.

—SA
 
Share this answer
 
Comments
ks ravi 14-Jun-11 23:57pm    
thanks for reply please give an example about this
Sergey Alexandrovich Kryukov 17-Jun-11 23:22pm    
???

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