Drop Down list question

R

Rudy

Hello all,

I made a drop down list, and bound it to a column, I then have a data grid
that is bound to a table. I would like to select from the ddl and whatever
is selected, that should show up in the data grid below. Here is my code.
Thanks for all the help!

Rudy

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

daProducts.Fill(DsProducts1)
grdProducts.DataBind()

If Not Page.IsPostBack Then
CategoryLoad()

ProductsLoad()

End If

End Sub

Private Sub CategoryLoad()
Dim ds As DataSet
Dim da As SqlDataAdapter


Dim strSQL As String = "SELECT CategoryName, CategoryID FROM
Categories"

ds = New DataSet
da = New SqlDataAdapter(strSQL, cnMidwest)
da.Fill(ds)

With ddlCategories
.DataTextField = "CategoryName"
.DataValueField = "CategoryID"
.DataSource = ds
.DataBind()

End With

End Sub

Private Sub ddlCategories_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlCategories.SelectedIndexChanged

ProductsLoad()

End Sub

Private Sub ProductsLoad()
Dim ds As DataSet
Dim da As SqlDataAdapter
Dim mycommand As New SqlCommand
mycommand.CommandText = "WHERE CategoryID = " &
ddlCategories.SelectedItem.Value




ds = New DataSet

With daProducts
mycommand.CommandType = CommandType.Text
.Fill(ds)
End With

With grdProducts
.DataSource = ds
.DataBind()

End With
End Sub
 
R

ranganh

Hi Rudy,

Now can you tell whatz actually happening with your code. Does it work or
does it throw some error or doesnt work as expected.

Thanks.
 
R

Rudy

Hi Ranganh,

Sorry about that, it was pretty late when I posted. I do not recieve any
errors. When everthing loads up, my grid is fine, and the drop down list
loads fine as well. When I do select a category from the drop down list, it
does do somthing, because the screen flashes, but nothin changes.
I'm taking a category name from one tables, and from another table called
products I'm loading all the columns in the data grid. In the drop down
list, has the category names, they should sync up with the category ID
number, and only show that product in that category below. I beleive I have
my tables set up right. I know it's just a small tweek, just not sure.

Thanks!

Rudy
 
R

ranganh

Hi,

can you please clarify on the following:-

1. What is the dsProducts1 in i.e. where have you declared the same.

daProducts.Fill(DsProducts1)
grdProducts.DataBind()

2. Where are you binding the where condition to your original sql statement
which populates the datagrid.

Thanks.
 

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,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top