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 functioning combo box with EasyListBox
by Peter Brunone

This example shows how to generate a simple combo box with some basic styling, and populate it from a SQL Server database.

The LimitToList attribute can be turned on to keep users from entering non-standard values.

   filename=/experiments/easylistbox/elb_combo.aspx

<Test Script Below>


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

    Sub Page_Load(Src As Object, E As EventArgs)
         If Not Page.IsPostBack Then
             Dim strConn as string = AppSettings("LearnaspSamples")
             Dim strSQL as string =" use northwind select ProductID, ProductName " & _
              "from [Current Product List] order by ProductName "

             Dim Conn As SqlConnection = New SQLConnection(strConn)
             Dim Cmd as New SQLCommand(strSQL,Conn)

             Conn.Open()

             myCombo.DataSource = Cmd.ExecuteReader()
             myCombo.DataBind()
         Else
             litComboValue.Text = "Selected: " & myCombo.SelectedValue & " / " & myCombo.SelectedText
         End If
    End Sub

</script>
<html>
    <head>
    <title>Combo box demo by EasyListBox.com</title>
    </head>
    <body bgcolor="#dddddd">
        <form id="mainForm" runat="server">
        <br /><br />
        <ELB:EasyListBox id="myCombo" runat="server"
         DisplayMode="combo"
         LimitToList="False"
         Width="250px"
         ButtonColor="#002299"
         ArrowColor="#f0f0f9"
         BackGround="#f0f0f9"
         TextColor="red"
         DataValueField="ProductID"
         DataTextField="ProductName"
         >
         </ELB:EasyListBox>
        <br />
        <input type="submit" value="Submit Form" />
        <br /><br />
        <asp:Literal id="litComboValue" runat="server" />
        </form>
    </body>
</html>
Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site