By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Urgently need help in drop down list..thanx

P: n/a
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

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200505/1
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Joey asre u doing Autopostback="true" in your DropDownList ?
See if that works
patrick

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #2

P: n/a
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

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200505/1
Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.