ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  ASP.NET Data Controls Part 1: DataGrids
Subject:   asp.net
Date:   2005-04-06 02:18:03
From:   wishi

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If (Not IsPostBack) Then
ddl_databind()


End If
End Sub


Public Sub ddl_databind()
Dim sqlcon As New SqlConnection("server=Shikhaws;user id=sa;password=sa;database=northwind")
Dim sqlcmd As New SqlCommand("SELECT FirstName,EmployeeId FROM Employees", sqlcon)
sqlcon.Open()
DropDownList1.DataSource = sqlcmd.ExecuteReader()
DropDownList1.DataTextField = "FirstName"
DropDownList1.DataValueField = "EmployeeId"
DropDownList1.DataBind()
sqlcon.Close()
End Sub
Public Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim sb As New StringBuilder
Dim ddl As New DropDownList
sb.Append("DropDownList1.selecteditem value=")
sb.Append(DropDownList1.SelectedItem.Value)
sb.Append("
")
sb.Append("dropdownlist.selecteditem=")
sb.Append(ddl.SelectedItem)
lblmessage.Text = sb.ToString()
Dim sqlcon As New SqlConnection("server=localhost;uid=sa;pwd=;database=northwind")
Dim ds As New DataSet
Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT Title FROM Employees where EmployeeId= " & DropDownList1.SelectedItem.Value, sqlcon)
da.Fill(ds, "EmployeeId")
TextBox1.Text = ds.Tables(0).Rows(0)("Title")


End Sub
End Class