E:\web\learnaspcom\htdocs\freebook\learn\ubtoc.xml LearnAsp.com - ASP ASP.net Free Lessons
Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll
<Asp.net blog>
<personal site>
xxx

Creating a set of functioning dependent list boxes with EasyListBox
by Peter Brunone

Here we create a couple of dependent lists using data from the Northwind database.

Notice the use of the DataFilterField property, which makes this extremely easy.

   filename=/experiments/easylistbox/elb_dependent.aspx

<Test Script Below>


<%@ Page Language="VB" EnableViewState="False" Debug="True" %>
<%@ Register TagPrefix="ELB" Namespace="ELB" Assembly="EasyListBox" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Configuration.ConfigurationSettings" %>
<script runat="server">

    Sub Page_Load(Src As Object, E As EventArgs)
        Dim strConn As String = AppSettings("LearnaspSamples")

        Dim strSQL As String = " Use Northwind SELECT ProductID, ProductName, UnitPrice, SupplierID, CategoryID " & _
        "FROM Products ORDER BY ProductName "

        Dim myAdapter As New SqlDataAdapter(strSQL, strConn)
        Dim dsNorthwind As New DataSet()

        ' Fill Products table in dataset
        myAdapter.Fill(dsNorthwind, "Products")

        ' Fill Suppliers table in dataset
        strSQL = "USE Northwind SELECT SupplierID, CompanyName, Country FROM Suppliers " & _
        " ORDER BY CompanyName "
        myAdapter = New SqlDataAdapter(strSQL, strConn)

        myAdapter.Fill(dsNorthwind, "Suppliers")

        'testGrid.DataSource = dsNorthwind.Tables("Products")
        'testGrid.DataBind()

        'litMsg.Text = elbProducts.DataFilterField

        elbProducts.DataSource = dsNorthwind.Tables("Products")
        elbProducts.DataBind()

        elbSuppliers.DataSource = dsNorthwind.Tables("Suppliers")
        elbSuppliers.DataBind()

    End Sub

</script>
<html>
    <head>
    <title>Parent/child (dependent) lists demo by EasyListBox.com</title>
    </head>
    <body bgcolor="#ffffff">
        <form id="mainForm" runat="server">
        <br /><br />
        <b>Suppliers (parent):</b><br />
        <ELB:EasyListBox id="elbSuppliers" runat="server"
         DisplayMode="listbox"
         Width="250px"
         DataValueField="SupplierID"
         DataTextField="CompanyName"
         DataTextField2="Country"
         ChildListName="elbProducts"
         >
         </ELB:EasyListBox>
        <br />
        <b>Products (child):</b><br />
        <ELB:EasyListBox id="elbProducts" runat="server"
         DisplayMode="listbox"
         Width="250px"
         DataValueField="ProductID"
         DataTextField="ProductName"
         DataTextField2="UnitPrice"
         DataFilterField="SupplierID"
         ParentList="elbSuppliers"
         >
         </ELB:EasyListBox>
        <br />
        <input type="submit" value="Submit Form" />
        <br /><br />
        <asp:Literal id="litMsg" runat="server" />
        <asp:DataGrid id="testGrid" runat="server" />
        </form>
    </body>
</html>
There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too. a $5 tip buys him lunch at McDonalds, a $20 tip buys his kid Hitoshi a new computer game, a $39 tip buys his daughter Michiko a few nice outfits. See our donor list.