问题下拉列表过滤列表框 [英] problem dropdownlist filtering a list box

查看:76
本文介绍了问题下拉列表过滤列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在DropDownList中选择某项时,我希望它更改ListBox中显示的内容.

我想做这样的事情:
示例
请参阅过滤器" DropDownList,它会更改其下面的列表框中的数据.

使用ASP.NET和VB最简单的方法是什么?
是否有与此相关的教程?
我创建了一个代码,但到目前为止还不好.
它仅显示下拉菜单的第一个默认文本,当您选择其他文本时,列表框为空白

When something is selected in a DropDownList, I want this to change what is displayed in a ListBox.

I would like to make something the same as this:
Example
Please see the "Filter" DropDownList which changes the data in the ListBox below it.

What is the easiest way to do this using ASP.NET and VB?
is there any tutorial regarding this?
I created a code but so far no good.
It only shows the first default text of the dropdown and when you choose another text the list box when blank

Dim strSQL As String
Dim connection As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
strSQL = "SELECT [CourseTitle] FROM [tblTrainingPlan] WHERE ([Category] LIKE '%' + @Category + '%')"
connection.Open()

Dim command As New SqlCommand(strSQL, connection)
command.Parameters.AddWithValue("@Category", ddcategory.SelectedValue)
cbTitle.DataSource = command.ExecuteReader
cbTitle.DataTextField = "CourseTitle"
cbTitle.DataValueField = "CourseTitle"
cbTitle.DataBind()
command.Dispose()
connection.Close()

推荐答案

如果在服务器端:

1.在不回发"的if条件内加载页面加载下拉列表(我们之前在您之前的问题中进行过讨论)
2.在下拉单击事件上加载并绑定列表框

如果在客户端(例如,在javascript中)
阅读
if on server side:

1. load the dropdown on page load inside the if condition of ''not postback'' (we discussed it before in your previous questions)
2. load and bind the listbox on the click event of dropdown

if on client side (i.e in javascript)
read this


<asp:DropDownList ID="ddcategory" runat="server" Height="27px" Width="293px" AutoPostBack="True">
    <asp:ListItem Value="4">Fluor University Functional Courses (instructor-led)</asp:ListItem>
    <asp:ListItem Value="1">GEE 51 Bulletin Requirements</asp:ListItem>
    <asp:ListItem Value="2">Cross Functional Courses</asp:ListItem>
    <asp:ListItem Value="3">Functional Courses (online)</asp:ListItem>
    <asp:ListItem Value="5">Local Functional Courses (instructor-led)</asp:ListItem>
    <asp:ListItem Value="6">External Courses</asp:ListItem>
    <asp:ListItem Value="7">Other Courses</asp:ListItem>
    <asp:ListItem></asp:ListItem>
</asp:DropDownList></div>


先生,这是我在dropdownlist上的代码.没有点击事件


Sir this is my code on dropdownlist . there is no click event


这篇关于问题下拉列表过滤列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆