hi all,

i'm hvng dropdownlist for country by getting values from Database(SQL SERVER).Now in Drop Downlist,the default value should be in "Select Your Country"...

I'm too new to .net.will u help me solve this issue..

Dis is in asp.net with vb

Thank u..

what the problem?
getting data from database or set default value in dropdown list?

Sorry, didn't see the new thread

After your datafill eg: Me.TestTableTableAdapter.Fill(Me.DataSet1.TestTable) - VB will generate this for you

use:
ComboBox1.Text = "Select Country"

set default value in dropdown list

ddlCountry.DataSource = getCountry()
ddlCountry.DataTextField = "Name"
ddlCountry.DataValueField = "ID"
ddlCountry.DataBind()

Actually i'm hvng dis code snippet to bind data..in drop down list...how to set the default value as "Select Country"

Private Sub loadCountry()
'
Try
'
ddlCountry.DataSource = getCountry()
ddlCountry.DataTextField = "Name"
ddlCountry.DataValueField = "ID"
ddlCountry.DataBind()
'
Catch ex As Exception
'
Throw ex
'
Finally
'
ddlCountry.Items.Add("Select Country")
ddlCountry.SelectedValue = "Select Country"
'
End Try
'
End Sub

totally nw i'm hving dis code snippet..dis is displaying every country bt d "Select Country" is coming bottom of the list

use this code to load data on dropdownlist

Private Sub ReadData()
        Dim i, k As Integer
        Dim cmdCountry As New SqlCommand
        Dim daCountry As New SqlDataAdapter
        Dim dsCountry As New DataSet
        Dim dtCountry As New DataTable
        Dim conn As SqlConnection

        conn = GetConnect()
        Try

            cmdCountry = conn.CreateCommand
            cmdCountry.CommandText = "SELECT * FROM TableName"
            daCountry.SelectCommand = cmdCountry
            daCountry.Fill(dsCountry, "TableName")
            dtCountry = dsCountry.Tables("TableName")
            For i = 0 To dtCountry.Rows.Count - 1
                CmbCountry.Items.Add(dtCountry.Rows(i).Item(0)) ' which item on table that u want to display in dropdwn list
            Next

        Catch ex As Exception
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Connection Error !!")
        End Try
        conn.Close()
    End Sub

to set default value :
CmbCountry.Text = "Select Country"

Jx_Man, when you use:
Dim conn As SqlConnection

can this only be used for MS SQL?

I'm using a Postgres database and this way seems a lot simpler? I'm using an ODBC connection string to connect at the moment.

this code for MS Sql.
i never tried it for postgres, just for access.