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
Over 500 ASP.NET 3.5 Interview Questions with Answers of DOT NET including ASP.NET,dotnet interview questions,Visual stdio 2008,download free e-book.
How fill drop down list in asp.net
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment