Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 6th, 2007, 12:56 PM
Authorized User
 
Join Date: Jan 2007
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Listbox,Postback and Datasource

Hello was wondering if anyone could give me some guidance. I am trying to use Two List Boxes and a gridview/detailview to develop a search ,function from the database. I'm struggling to construct this.

At present the first listbox list the categories and the second listbox list all the item that belong to all of categories.

I have selected autopost to true on both list because the page will need to be refreshed when a category or item is selected.

when the page first loads I want all the of the items to be displayed in listbox two. Then when a specific catergory is selected from listbox one I want the items within this catergory to be displayed in listbox two.

The next stage follows a similiar process, except it involves using a gridview/detailsview. When an item is selected in listbox two, I have an autopost set to true so the page refreshes and I want the gridview to display the detail relevant to that item.

Can anyone provide me with an example of how to do this, It would really help me with the site I'm working on.Does anyone know of any tutorial that do what I am trying to achieve. Really urgent that I get this done, so any help will be very helpful.

Thanks


 
Old March 6th, 2007, 01:36 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

A tutorials specific to this, no. What you need to do is:

Create a method to handle the postback of lb1 and populate lb2 the method that handles the postback of lb2 should, i would assume, get the value of lb1 and lb2, create a query for you database, execute that query, then bind the gridview to the resultset.

This isnt to terribly difficult but doing google searches on the Listbox postback method and how to bind data to a gridview should get you moving along.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 6th, 2007, 05:04 PM
Authorized User
 
Join Date: Jan 2007
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are there any example of how to set up a postback method for listbox.
I'm really new to asp.net and not at all sure what I'm doing.

How do I go about creating the method for listbox1 so that when the user select a category for example listbox one contains different type of cars manufacturers. i.e. vauxhall,renault, ford etc.


The user selects vauxhall in listbox1 and listbox2 populates with the different vauxall car models tigra, astra, omega, corsa.

The user then click on the car model to view the detail about that particular model in a gridview or detailview box

This what I trying to do, I know what I want to just not sure how to do this. At all is possible to have a example of the scenario i showed that I can look at. Or a step by step description of the process I need to follow to generate what I am trying to achieve.

This would be very much appreciated. Thanks



 
Old March 6th, 2007, 05:41 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

I think you're talking about something like this:

    Frontpage code:

    <asp:DropDownList ID="ddlABCID" AutoPostBack="True" Runat="server" />

    <asp:DropDownList ID="ddlXYZID" AutoPostBack="True" Runat="server" />

    [Grid tags]

    Code behind:

    Sub getABCID()
        Dim SQL As String = "[SELECT statement to populate first list-box;]"
        Dim oDA As New SqlDataAdapter(SQL, _oConn)
        Dim oDS As New DataSet
        oDA.Fill(oDS)
        ddlABCID.DataSource = oDS
        ddlABCID.DataTextField = "[Field you want to display.]"
        ddlABCID.DataValueField = "[Database ID of the item so that when it is selected you can repopulate the second list box.]"
        ddlABCID.DataBind()
        ddlABCID.Items.Insert(0, New ListItem("All", 0))
        ddlXYZID.Items.Insert(0, New ListItem("All", 0))
        grdGridDisplay.Visible = False
    End Sub

    Private Sub ddlABCID_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlABCID.SelectedIndexChanged
        ddlXYZ.Items.Clear()
        getXYZID(ddlABCID.SelectedValue)
        grdGridDisplay.Visible = False
    End Sub

    Sub getXYZID(ByVal ABCID As Integer)
        Dim SQL As String = "[SELECT statement to populate second list box.]"
        Dim oDA As New SqlDataAdapter(SQL, _oConn)
        Dim oDS As New DataSet
        oDA.Fill(oDS)
        ddlXYZID.DataSource = oDS
        ddlXYZID.DataTextField = "[Field you want to display.]"
        ddlXYZID.DataValueField = "[Database ID of the item so that when it is selected you can repopulate the second list box.]"
        ddlXYZID.DataBind()
        ddlXYZID.Items.Insert(0, New ListItem("All", 0))
        grdGridDisplay.Visible = False
    End Sub

    Public Sub ddlXYZID_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlXYZID.SelectedIndexChanged
        getGridDisplay(ddlXYZID.SelectedValue)
    End Sub

    Sub getGridDisplay(XYZID As Integer)
        'Code to populate to bind data to your grid.
        grdGridDisplay.Visible = False
    End Sub

 
Old March 10th, 2007, 12:28 PM
Authorized User
 
Join Date: Jan 2007
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks I figured out how to do it, just viewed this reply today. I'm sure it will be useful for future reference. This is very much appreciated. Thanks

 
Old March 22nd, 2007, 04:13 AM
Registered User
 
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shahnila
Default

Nichola has asked question about populating two drop down list.I am also working on same type of project but the code that has been sent is not working properly.like grdGridDisplay is not declared error and many function's error.Please send me clear code about twwo drop down list when first (Product) one is select other (Category)will change according to product and these two table Product and Category are in one to many relationship.






Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple Listbox values in another listbox terryv Excel VBA 0 June 27th, 2007 07:01 AM
Arraylist is datasource for listbox. Failing. CharissaJB C# 2005 0 September 14th, 2006 10:33 AM
Problem with listbox postback jlechem ASP.NET 1.0 and 1.1 Basics 18 July 28th, 2006 03:31 PM
Object datasource VS DataSource SoftMind BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 4 July 27th, 2006 10:44 PM
ListBox DataSource jugomkd C# 2 October 9th, 2004 11:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.