Urgently need help in drop down list..thanx

Discussion in 'ASP .Net' started by Joey Liang via DotNetMonster.com, May 24, 2005.

  1. 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/Forums.aspx/asp-net/200505/1
    Joey Liang via DotNetMonster.com, May 24, 2005
    #1
    1. Advertising

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



    *** Sent via Developersdex http://www.developersdex.com ***
    Patrick Olurotimi Ige, May 24, 2005
    #2
    1. Advertising

  3. 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/Forums.aspx/asp-net/200505/1
    Joey Liang via DotNetMonster.com, May 24, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SirPoonga
    Replies:
    2
    Views:
    742
    Ben Strackany
    Jan 7, 2005
  2. weiwei
    Replies:
    0
    Views:
    1,001
    weiwei
    Jan 5, 2007
  3. msimmons
    Replies:
    0
    Views:
    458
    msimmons
    Jul 16, 2009
  4. Replies:
    5
    Views:
    253
  5. Replies:
    3
    Views:
    275
Loading...

Share This Page