Display data in datagrid using dropdown selection

  • Thread starter priyanka.freakout
  • Start date
P

priyanka.freakout

Hi All,

In my form I have created a dropdown box which is populated with data
from a database on page load and i have also created a dropdwon box and
what i intend on doing is displaying data re;ated to dropdown selection
into a data grid.

I have attached part of the code.

Can someone please help me out on this cos i am really finding it
difficult doing it with the data reader.

Public Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged

Dim str As String
Dim sqlstr As String
Dim ds As DataSet
Dim ds1 As New DataSet

Dim sqlcmd As New SqlClient.SqlCommand
Dim dataadp As New SqlClient.SqlDataAdapter

SqlConnection1.Open()
str = DropDownList1.SelectedItem.Text
Label1.Text = str

sqlstr = "select * from Resources where Module_name=" + str
Label3.Text = sqlstr
sqlcmd = New SqlClient.SqlCommand(sqlstr, SqlConnection1)
dataadp = New SqlClient.SqlDataAdapter(sqlcmd)
dataadp.SelectCommand.Connection = SqlConnection1
SqlCommand1.CommandText = sqlstr
SqlCommand1.ExecuteReader()
 
O

OHM \( One Handed Man \)

Something like this to fill a dataset & Change the query selection depending
on the value of a dropdownlist

Dim sqlString As String = "SELECT * FROM People where person='" &
drpPeopleDropDown.SelectedValue & "';"
Dim sqlDA As New SqlClient.SqlDataAdapter
Dim sqlCommand As New SqlCommand(sqlString, sqlConnection)
Dim Peopl as New Dataset
sqlDA.SelectCommand = sqlCommand

Try
sqlConnection.Open()
sqlDA.Fill(People)
Catch ex As Exception
'TODO exception handling
Finally
sqlConnection.Close()
End Try

Then bind a DataGrid to the dataset

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top