Javascript 当用户单击下拉列表中的其他选项时,更改页面内容
我有一个下拉列表。用户选择不同的值后,我应该从下拉列表中获取用户选择的选项文本,然后从数据库中查找数据并在网页上显示相关内容。如果用户再次更改选项,我应该根据选择的选项文本检索不同的数据,并在网页上显示不同的内容 我怎样才能做到这一点?有人能让我开始吗?我在网上搜索过,但没有找到任何有用的东西 这是我的密码: ASPX文件:Javascript 当用户单击下拉列表中的其他选项时,更改页面内容,javascript,c#,asp.net,listbox,dropdown,Javascript,C#,Asp.net,Listbox,Dropdown,我有一个下拉列表。用户选择不同的值后,我应该从下拉列表中获取用户选择的选项文本,然后从数据库中查找数据并在网页上显示相关内容。如果用户再次更改选项,我应该根据选择的选项文本检索不同的数据,并在网页上显示不同的内容 我怎样才能做到这一点?有人能让我开始吗?我在网上搜索过,但没有找到任何有用的东西 这是我的密码: ASPX文件: <asp:Dropdownlist ID="SelectionDropDownList" runat="server" Widt
<asp:Dropdownlist ID="SelectionDropDownList"
runat="server" Width="136px"
EnableViewState="True"
AppendDataBoundItems="true">
</asp:Dropdownlist>
//how the dropdown list is being populated out. Dropdown list is being populated out from what the user has selected from a listbox.
public void BindSomething()
{
DateTime choosenDate = DateTime.MinValue;
using (SqlConnection conn = new SqlConnection(dbConn))
{
using (SqlCommand cmd = new SqlCommand(spretrieve, conn))
{
//Lost to hold the values
List<DateTime> listCopy = new List<DateTime>();
DateTime dt;
string values = String.Join(", ", ListBox1.Items.Cast<ListItem>().Where(i => i.Selected).Select(i => i.Text));
if (values.Contains("Select All"))
{
//Loop through each items in listbox and then add it to list
foreach (ListItem li in ListBox1.Items)
{
if (DateTime.TryParse(li.Text, out dt))
{
listCopy.Add(dt);
}
}
}
else
{
//Loop through each items in listbox and then add it to list
foreach (ListItem li in ListBox1.Items)
{
//check if item is selected
if (li.Selected == true)
{
//add items to list
listCopy.Add(DateTime.Parse(li.Text));
}
}
}
//compare and sort so that the latest date comes on top
listCopy.Sort((x, y) => y.CompareTo(x));
//clear the items in dropdownlist
SelectionDropDownList.Items.Clear();
//set the datasource to dropdownlist
SelectionDropDownList.DataSource = listCopy;
//set the dateformatstring in dropdownlist
SelectionDropDownList.DataTextFormatString = "{0:dd-MMM-yyyy}";
//Bind the dropdownlist
SelectionDropDownList.DataBind();
}
CS文件:
<asp:Dropdownlist ID="SelectionDropDownList"
runat="server" Width="136px"
EnableViewState="True"
AppendDataBoundItems="true">
</asp:Dropdownlist>
//how the dropdown list is being populated out. Dropdown list is being populated out from what the user has selected from a listbox.
public void BindSomething()
{
DateTime choosenDate = DateTime.MinValue;
using (SqlConnection conn = new SqlConnection(dbConn))
{
using (SqlCommand cmd = new SqlCommand(spretrieve, conn))
{
//Lost to hold the values
List<DateTime> listCopy = new List<DateTime>();
DateTime dt;
string values = String.Join(", ", ListBox1.Items.Cast<ListItem>().Where(i => i.Selected).Select(i => i.Text));
if (values.Contains("Select All"))
{
//Loop through each items in listbox and then add it to list
foreach (ListItem li in ListBox1.Items)
{
if (DateTime.TryParse(li.Text, out dt))
{
listCopy.Add(dt);
}
}
}
else
{
//Loop through each items in listbox and then add it to list
foreach (ListItem li in ListBox1.Items)
{
//check if item is selected
if (li.Selected == true)
{
//add items to list
listCopy.Add(DateTime.Parse(li.Text));
}
}
}
//compare and sort so that the latest date comes on top
listCopy.Sort((x, y) => y.CompareTo(x));
//clear the items in dropdownlist
SelectionDropDownList.Items.Clear();
//set the datasource to dropdownlist
SelectionDropDownList.DataSource = listCopy;
//set the dateformatstring in dropdownlist
SelectionDropDownList.DataTextFormatString = "{0:dd-MMM-yyyy}";
//Bind the dropdownlist
SelectionDropDownList.DataBind();
}
//如何填充下拉列表。正在从用户从列表框中选择的内容填充下拉列表。
公共关系
{
DateTime choosenDate=DateTime.MinValue;
使用(SqlConnection-conn=newsqlconnection(dbConn))
{
使用(SqlCommand cmd=newsqlcommand(spretrieve,conn))
{
//失去了持有价值观
List listCopy=新列表();
日期时间dt;
字符串值=string.Join(“,”,ListBox1.Items.Cast()。其中(i=>i.Selected)。选择(i=>i.Text));
if(values.Contains(“全选”))
{
//循环浏览列表框中的每个项目,然后将其添加到列表中
foreach(ListBox1.Items中的ListItem li)
{
if(DateTime.TryParse(li.Text,out dt))
{
添加(dt);
}
}
}
其他的
{
//循环浏览列表框中的每个项目,然后将其添加到列表中
foreach(ListBox1.Items中的ListItem li)
{
//检查项目是否已选中
如果(li.Selected==true)
{
//将项目添加到列表中
Add(DateTime.Parse(li.Text));
}
}
}
//比较和排序,以便最新日期出现在顶部
排序((x,y)=>y.CompareTo(x));
//清除dropdownlist中的项目
SelectionDropDownList.Items.Clear();
//将数据源设置为dropdownlist
SelectionDropDownList.DataSource=listCopy;
//在dropdownlist中设置dateformatstring
SelectionDropDownList.DataTextFormatString=“{0:dd-MMM-yyyy}”;
//绑定下拉列表
SelectionDropDownList.DataBind();
}
如果有人能在这方面帮助我,我将不胜感激!!您可以尝试使用jQuery
$(document).ready(function() {
$('#SelectionDropDownList').change(function(){
//here you can add code for whatever you want to show
});
});
我希望这对你有帮助