Debmedia Creation Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

asp.net To Get all country name in a dropdown

Go down

asp.net To Get all country name in a dropdown Empty asp.net To Get all country name in a dropdown

Post  Admin Mon Feb 08, 2010 2:27 pm

To Get all country name in a dropdown list in asp.net to create a registration form:

You have to take a dropdown list called "cbocountry"

Code are as follows:

Imports System.Globalization
Partial Class _Default
Inherits System.Web.UI.Page
Dim f_Value As String
'Protected WithEvents cboCountry As System.Web.UI.WebControls.DropDownList
Const DEFAULT_COUNTRY = "India"
Private Function first_load() As String
Dim ci As CultureInfo
Dim str As String
Dim intPos As Integer
Dim intPosDefault As Integer
For Each ci In CultureInfo.GetCultures(CultureTypes.SpecificCultures)
str = ci.DisplayName
intPosDefault = InStr(str, "(")
str = Mid(str, intPosDefault + 1, Len(str) - intPosDefault - 1)
intPos = InStr(str, "(")
If intPos > 0 Then
str = Mid(str, intPos + 1, Len(str) - intPos)
End If
If cboCountry.Items.Count > 0 Then
Dim CheckItem = cboCountry.Items.FindByText(str)
If CheckItem Is Nothing Then
cboCountry.Items.Add(str)
End If
Else
cboCountry.Items.Add(str)
End If
Next ci
cboCountry.SelectedIndex = cboCountry.Items.IndexOf(cboCountry.Items.FindByText(DEFAULT_COUNTRY))
f_Value = cboCountry.SelectedValue
Return cboCountry.SelectedValue
End Function
Public Sub DefaultValue()
Me.cboCountry.SelectedValue = DEFAULT_COUNTRY
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
first_load()
End Sub
Public Property Value() As String
Get
Return f_Value
End Get
Set(ByVal Value As String)
f_Value = Value
cboCountry.SelectedIndex = cboCountry.Items.IndexOf(cboCountry.Items.FindByText(f_Value))
End Set
End Property
Private Sub cboCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCountry.SelectedIndexChanged
f_Value = cboCountry.SelectedValue
End Sub
End Class
Admin
Admin
Admin

Posts : 256
Join date : 2008-06-06

https://debmedia.forumotion.com

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum