The GetSelectList method makes it easy to create a drop down list in your web forms for country selection.
By default, the list box will contain all countries as defined in the "select.hosts" line in your countries.properties file. Also by default, the country corresponding to the current visitor is automatically selected in the list. If you wish you can edit the select.hosts line to narrow down the list of countries to remove some of the countries that you do not expect visitors from (by default there are over 240 countries listed).
You can also control the order in which the country names appear in the list by changing the order listed in the select.hosts line of the properties file. For example, if the majority of your visitors are from the United Kingdom, move UK to the front of the list in the select.hosts line.
There are also several optional parameters you can use to customize this method's behavior, such as setting the form field name, countries to list, list order, and more.
Syntax:
html = chObj.GetSelectList()
Returns a string containing the HTML to create a country drop down box selection list with all countries included as specified in the select.hosts line of the countries.properties file.
html = chObj.GetSelectList(string codes)
Returns a string containing the HTML to create a country drop down box selection list with only the specified countries listed. The codes parameter must contain a list of comma separated two-letter country codes as defined in the countrynames.properties file.
html = chObj.GetSelectList(string codes, string autoSel)
Returns a string containing the HTML to create a country drop down box selection list with only the specified countries listed and a specific country selected in the list by default. The codes parameter must contain a list of comma separated two-letter country codes as defined in the countrynames.properties file; autosel must contain the two-letter country code for the country you want selected by default.
html = chObj.GetSelectList(string selectTagSuffix, string fieldName, bool useNamesInList, string codesForList, string countryToAutoSel, string countryPrefix)
Returns a completely customizable down box selection list as follows:
selectTagSuffix - Pass in any string you wish to be included after the opening SELECT tag. Consider this output:
<select name="country" XXXXX>
By default there will be no text where the XXXXX appears above. However you may wish to insert JavaScript or DHTML tags and attributes to be applied to this field. For example, say you wish to fire a JavaScript event after the user changes the select list, and say you want to set the field to a style sheet class defined elsewhere in your page. In this case you would pass in something like this in this parameter:
"onChange='myEvent()' class=myClass".
That would result in that string being inserted where the XXXX appears above.
fieldName - Use this parameter if you wish to change the field name assigned by the component from "country" to something else. For example, if you wish to use the name "EndUserCountry" because that's what your current web form already uses, pass that as a string to this parameter. Instead of:
<select name="country">
this would result in:
<select name="EndUserCountry">
useNamesInList - Pass in True if you wish to use the country names as the values posted by the form, instead of the country code which is the default. For example, with the default value of False this method will generate:
<select name="country"><option value="US">United States ... </select>
If you pass in True, this will generate:
<select name="country"><option value="United States">United States ... </select>
codesForList - By default the list and order of countries that appears in the select list is obtained from the "select.hosts" property in the countries.properties file. However there may be times when you wish to override this with a different list at run-time depending on conditions. For example, you may wish to include
a different set or order of countries at run-time. To use this parameter, pass in a list of two letter country codes separated by spaces. If you pass in an invalid country code, component will throw an InvalidArgException.
countryToAutoSel - By default the component will automatically select the user's country as the default selection in the list. However there may be times when you wish to override this behavior and explicitly tell the component which country to select. To change the default, pass in the two letter country code for the country you wish to be selected.
countryPrefix - This field is handy if you wish to add a prefix to each country name that is displayed in the list. For example, some developers like to add a couple of spaces to the left of the country name for cosmetic purposes. Or you may wish to add a marker next to each name, such as "-> ".
Returns:
This method returns a string containing HTML. You should then write the value of this string out to the browser in the appropriate place within your web form where you want the drop down list box to appear.
VB.NET Example:
dim chObj as CountryObj = CountryObj.GetCountry()
dim listboxHTML as string = chObj.GetSelectList()
Response.Write("<form>" + listboxHTML + "</form>")
C# Example:
CountryObj chObj = CountryObj.GetCountry();
String listboxHTML = chObj.GetSelectList();
Response.Write("<form>" + listboxHTML + "</form>");
Note: See the ch_listbox_vb.aspx and ch_listbox_custom_vb.aspx samples for more information.
Note: Use of the method signatures other than the default GetSelectList() signature requires the Professional or Enterprise Edition.