asp.net To Get all country name in a dropdown
Page 1 of 1
asp.net To Get all country name in a dropdown
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
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
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum