How fill drop down list in asp.net

Dim myconnection As SqlConnection
Dim myda As
SqlDataAdapter
Dim ds As
DataSet
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase
.Load
myconnection = New
SqlConnection("Server=localhost;uid=sa;password=;database=northwind;")
myda = New
SqlDataAdapter("Select * from CategoryTable ", myconnection)
ds = New
DataSet
myda.Fill(ds, "AllTables")
DropDownList1.DataSource = ds
DropDownList1.DataSource = ds.Tables(0)
DropDownList1.DataTextField = ds.Tables(0).Columns("CategoryName").ColumnName.ToString()
DropDownList1.DataValueField = ds.Tables(0).Columns("CategoryId").ColumnName.ToString()
DropDownList1.DataBind()
Dim i As
Integer
For i = 0 To
DropDownList1.Items.Count - 1
DropDownList1.Items(i).Attributes.Add("style", "color:" + ds.Tables(0).Rows(i)"CategoryColor").ToString())
Next
End Sub

No comments: