you can bind drop down box to any table from your database
1) create sql sever conection object
2) create command for fetch data from table, Adapter and Dataset object
3) fill your Dataset
4) dropdown1.datasourse = ds
5) dropdown1.datavalue = field name
dropdown1.datatext = field name
6) dropdown1.databind()
- con = New SqlConnection(ConnectionStrings)
-
con.Open()
-
cmd = New SqlCommand("Select query")
-
da = new sqldataadapter(cmd,con)
-
da.fill(ds)
-
dropdown1.datasourse = ds
-
dropdown1.DatavalueField = "field name"
-
dropdown1.DataTextField = "field name"
-
dropdown1.databind()
-
-
or
-
-
con = New SqlConnection(ConnectionStrings)
-
con.Open()
-
cmd = New SqlCommand()
-
cmd.Connection = con
-
cmd.CommandText = ""
-
Rs = cmd.ExecuteReader()
-
cboLocation.Items.Clear()
-
'cboLocation.Items.Add("Select")
-
'Response.Write("rt " & strloc)
-
If Rs.HasRows Then
-
cnt = 0
-
While (Rs.Read())
-
cboLocation.Items.Add(Rs(0).ToString())
-
If strloc = (Rs(0).ToString()) Then
-
i = cnt
-
txtIP.Text = Rs(1).ToString()
-
txtCno.Text = Rs(2).ToString()
-
End If
-
cnt = cnt + 1
-
End While
-
End If