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
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