Urgently need help in drop down list..thanx

  • Thread starter Joey Liang via DotNetMonster.com
  • Start date
J

Joey Liang via DotNetMonster.com

Hi all,
I am new in asp.net, i encounter some problems in using drop down
list and datagrid. I have manage to bind the data into datagrid but i
wanted to bind the data into the datagrid accroding to the selected brand
from the drop down list. I do not have any idea how to do it. Does anyone
knows how to bind the data in to datagrid accroding to the drop down list
selected item? if there is a way would u mind paste the code or any
tutorials regarding this so that i can refer.

Here is e code i write but seemd ro have some logic error..when i select an
item in the drop down list,there is no response..Anyone knows which part of
the code that goes wrong?Thanx in advance



Private Sub ddlBrand_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ddlBrand.SelectedIndexChanged

Dim strSqlCmd As String
Dim objAdp As OleDb.OleDbDataAdapter
Dim dataTable As DataTable
Dim brand As String

brand = ddlBrand.SelectedItem.Value

strSqlCmd = "Select p.ProductID, p.ProductName,p.ProductBrand, " & _
"p.ProductImage, p.Price, p.Quantity " & _
"From Product p, CategoryProduct cp Where " & _
"p.ProductID= cp.productID " & _
"and cp.CategoryID=" & Request.QueryString.Get("CategoryID")
& _"and p.ProductBrand=" & brand

objAdp = New OleDb.OleDbDataAdapter(strSqlCmd, con)
dataTable = New DataTable
objAdp.Fill(dataTable)
dgProducts.DataSource = dataTable
dgProducts.DataBind()


End Sub

Thanx,
Joey
 
P

Patrick Olurotimi Ige

Joey asre u doing Autopostback="true" in your DropDownList ?
See if that works
patrick
 
J

Joey Liang via DotNetMonster.com

I use If Not IsPostBack.. here is the code which is more detailed than the
early code i posted. Do you have any idea how to make it work? Thanx..

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
GetProductDetails()
GetProductbrand()
GetCategory()
GetDepartment()
End If
End Sub


Private Sub GetProductbrand()
'Bind Category's products brands from the database to ddlBrand
Dim strSqlCmd As String
Dim objAdp As OleDb.OleDbDataAdapter
Dim dataTable As DataTable
strSqlCmd = "Select Distinct p.ProductBrand " & _
"From Product p, CategoryProduct cp Where " & _
"p.ProductID= cp.productID " & _
"and cp.CategoryID=" & Request.QueryString.Get
("CategoryID")

objAdp = New OleDb.OleDbDataAdapter(strSqlCmd, con)
dataTable = New DataTable
objAdp.Fill(dataTable)
ddlBrand.DataSource = dataTable
ddlBrand.DataMember = "Product"
ddlBrand.DataTextField = "ProductBrand"
ddlBrand.DataBind()

ddlBrand.Items.Insert(0, "Show All")
ddlBrand.SelectedIndex = 0

End Sub

Private Sub ddlBrand_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ddlBrand.SelectedIndexChanged

Dim strSqlCmd As String
Dim objAdp As OleDb.OleDbDataAdapter
Dim dataTable As DataTable
Dim brand As String

brand = ddlBrand.SelectedItem.Value

strSqlCmd = "Select p.ProductID, p.ProductName, p.ProductBrand, " &
_
"p.ProductImage, p.Price, p.Quantity " & _
"From Product p, CategoryProduct cp Where " & _
"p.ProductID= cp.productID " & _
"and cp.CategoryID=" &
Request.QueryString.Get("CategoryID") & _
"and p.ProductBrand=" & brand

objAdp = New OleDb.OleDbDataAdapter(strSqlCmd, con)
dataTable = New DataTable
objAdp.Fill(dataTable)
dgProducts.DataSource = dataTable
dgProducts.DataBind()


End Sub
 

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,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top