473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Urgently need help in drop down list..thanx

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
2 2085
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: carramba | last post by:
Hi! is it possible to change "selector" color in drop-down list? <select name="select" style="background-color: #ff0000"> <option style="background-color: #ff0000" value="1">Cony</option>...
3
by: Mike | last post by:
I have a web page that displays contact people in a drop down. the users selects a person then clicks the go button. The datagrid should pop with all the information on the select contact person,...
2
by: CW | last post by:
In an earlier thread, I was asking for help on "Invalid attempt to FieldCount when reader is closed" error when I was using a dataset rather than a datareader to bind to a datagrid. After...
3
by: Don Wash | last post by:
Hi There! I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to widen the Drop down box's Pull-Down list's width? I'm not talking about the Drop-down box's width but the box...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
6
by: Joey Liang via DotNetMonster.com | last post by:
Hi all, I have a drop down list which store all the different brands of product.When i selected the particular brand from the drop down list, it will display all the products with the selected...
1
by: ashok76 | last post by:
Hi I've a DataGridView and where has column 0 is a DataGridViewComboBoxColumn Whenever I selected that cell then the drop down list not appeared on single click event hence I need to click again...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
3
by: Gaurav Tandon | last post by:
I have dozens of drop down list in my application.Now i want to add a style to drop down that evey alternate item in drop down should be of red color ... I dont want to iterate drop down every...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.