|
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
<%@ 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>
|