![](/img/trans.png)
[英]ASP.Net C#, Is it possible to filter a Listview based on a DropDownList?
[英]Dropdownlist based on dropdownlist C# Asp.Net
我有 3 個下拉列表,並且我已經根據下拉列表 1 的SelectedValue
設置了下拉列表 2,但是我的下拉列表 3 沒有基於下拉列表 2 中的選擇的響應
if(DropDownList1.SelectedValue =="1")
{
DropDownList2.Items.Clear();
DropDownList2.Items.Insert(0, new ListItem("A", ""));
DropDownList2.Items.Insert(1, new ListItem("B", ""));
}
這就是我如何根據Dropdownlist1
Dropdownlist2
添加項目,但它在第三個下拉列表中不起作用,在我 select A 在Dropdownlist2
之后沒有任何項目:
if (DropDownList2.SelectedValue == "0")
{
DropDownList3.Items.Clear();
DropDownList3.Items.Insert(0, new ListItem("A-1", ""));
}
我認為您selectedvalue
的值錯誤,我認為它應該是selectedindex
if (DropDownList2.SelectedIndex == 0)
{
DropDownList3.Items.Clear();
DropDownList3.Items.Insert(0, new ListItem("A-1", ""));
}
如果您仍想使用selectedvalue
,請將new ListItem("A", "")
的綁定更改為new ListItem("A", "");
//populate first ddl with corret item and value
if(DropDownList1.SelectedValue =="1")
{
DropDownList2.Items.Clear();
DropDownList2.Items.Insert(0, new ListItem("A", ""));
DropDownList2.Items.Insert(1, new ListItem("B", ""));
}
if (DropDownList2.SelectedValue == "A")
{
DropDownList3.Items.Clear();
DropDownList3.Items.Insert(0, new ListItem("A-1", ""));
}
DropdownList.Items.Insert
實現ddl.Items.Insert(indexPosition, new ListItem("displayItem", "value");
因此,由於您在selectedvalue
中搜索“0”,在您的示例中它不存在,因為new ListItem("A", "")
它不會執行里面的語句
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.