我需要用listbox控件,显示符合dropdownlist控件或textbox控件中的值的条件,请问如何设置
比如我可以通过dropdownlist控件选择AA,然后在listbox中列出AA 下面的AA1 AA2 AA3
也可以直接输入AA 然后在listbox中显示AA1 AA2 AA3
使用2种方法中的一种即可 表如下
AA---AA1
AA2
AA3
BB---BB1
BB2
BB3
vs2008+SQL2008
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="App_User_test" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 73px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
选择系列:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource1" DataTextField="mingcheng"
DataValueField="mingcheng">
</asp:DropDownList>
手动输入:<asp:TextBox ID="TextBox1" runat="server"
ontextchanged="TextBox1_TextChanged" Width="83px"></asp:TextBox>
<br />
<br />
<br />
<br />
<br />
<p>
<table class="style1">
<tr>
<td valign=top class="style2">
选择型号</td>
<td>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource2" DataTextField="address" DataValueField="address"
Height="241px"></asp:ListBox>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
</td>
</tr>
</table>
</p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MuserConnectionString2 %>"
SelectCommand="SELECT DISTINCT [mingcheng] FROM [test]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:MuserConnectionString2 %>"
SelectCommand="SELECT [mingcheng], [address] FROM [test] WHERE (([mingcheng] = @mingcheng) AND ([address] = @address))">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="mingcheng"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="TextBox1" Name="address" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
比如我可以通过dropdownlist控件选择AA,然后在listbox中列出AA 下面的AA1 AA2 AA3
也可以直接输入AA 然后在listbox中显示AA1 AA2 AA3
使用2种方法中的一种即可 表如下
AA---AA1
AA2
AA3
BB---BB1
BB2
BB3
vs2008+SQL2008
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="App_User_test" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 73px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
选择系列:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource1" DataTextField="mingcheng"
DataValueField="mingcheng">
</asp:DropDownList>
手动输入:<asp:TextBox ID="TextBox1" runat="server"
ontextchanged="TextBox1_TextChanged" Width="83px"></asp:TextBox>
<br />
<br />
<br />
<br />
<br />
<p>
<table class="style1">
<tr>
<td valign=top class="style2">
选择型号</td>
<td>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource2" DataTextField="address" DataValueField="address"
Height="241px"></asp:ListBox>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
</td>
</tr>
</table>
</p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MuserConnectionString2 %>"
SelectCommand="SELECT DISTINCT [mingcheng] FROM [test]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:MuserConnectionString2 %>"
SelectCommand="SELECT [mingcheng], [address] FROM [test] WHERE (([mingcheng] = @mingcheng) AND ([address] = @address))">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="mingcheng"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="TextBox1" Name="address" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货