Please add one dropdownlist and set Autopostback = true in its properties. Also add a datagrid.
Public Partial Class WebForm3
Inherits System.Web.UI.Page
Public oCn As New System.Data.SqlClient.SqlConnection("Data Source=(local);Initial Catalog=MyDatabase;Uid=sa")
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Me.IsPostBack = False Then
fill_ddl()
End If
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
fill_data()
End Sub
Sub fill_data()
If oCn.State = ConnectionState.Closed Then
oCn.Open()
End If
Dim cmd As New SqlClient.SqlCommand("select * from mst_employees where name='" & Me.DropDownList1.SelectedItem.Text & "'", oCn)
Dim da As New SqlClient.SqlDataAdapter(cmd)
Dim ds As New DataSet("bpl")
Dim i As Integer = 0
da.Fill(ds, "bpl")
Me.GridView1.DataSource = ds.Tables(0)
Me.GridView1.DataBind()
oCn.Close()
End Sub
Sub fill_ddl()
If oCn.State = ConnectionState.Closed Then
oCn.Open()
End If
Dim cmd As New SqlClient.SqlCommand("select name from mst_employees", oCn)
Dim da As New SqlClient.SqlDataAdapter(cmd)
Dim ds As New DataSet("bpl")
Dim i As Integer = 0
da.Fill(ds, "bpl")
If ds.Tables(0).Rows.Count > 0 Then
Me.DropDownList1.Items.Add("Select an Item")
While (i <> ds.Tables(0).Rows.Count)
Me.DropDownList1.Items.Add(ds.Tables(0).Rows(i).Item("Name").ToString)
i = i + 1
End While
End If
Me.DropDownList1.DataBind()
oCn.Close()
End Sub
End Class