我正在尝试使用两个DropDownLists来过滤数据。我将OnSelectedIndexChanged
Equal设置为以下方法。问题是它只抓取了被更改的DDL SelectedIndex
。示例:如果我在DDL1中选择一个选项,它会抓取该值并且不会获取DDL2的值。他们都有相同的OnSelectedIndexChanged
我认为它会抓住两者的当前值。有没有办法让它看到两个DDL控件?
protected void BrandsList_SelectedIndexChanged(object sender, EventArgs e)
{
int DDLcatId = CategoriesList.SelectedIndex;
int DDLBraId = BrandsList.SelectedIndex;
IQueryable<Product> DDLprodResult = GetProductsDDL(DDLcatId, DDLBraId);
if(DDLprodResult == null)
{
}
else
{
CatLab.Text = DDLprodResult.ToList().Count().ToString();
productList.DataSource = DDLprodResult.ToList();
productList.DataBind();
}
}
答案 0 :(得分:1)
您的代码应该有效。当然,如果您在两者上都设置了AutoPostBack="true"
(默认为false),则只能更改一个。但是你应该在处理程序中得到正确的SelectedIndex
。
所以我猜:你在每次回发中都是DropDownLists
的数据绑定。仅执行if(!IsPostBack)
,否则您始终使用原始值覆盖更改。
例如在Page_Load
:
protected void Page_Load(Object sender, EvengtArgs e)
{
if(!IsPostBack)
{
// DataBind your DropDownLists
}
}