0
目前我正在使用下面的代碼來根據我在下拉列表中選擇的內容來過濾我的gridview,該下拉列表正在調用填充它的SQL語句。是否有另一種方法來過濾網格視圖?
protected void SetYear(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
if (filter != null)
{
if (filter.ContainsKey("Year 1"))
{
foreach (ListItem li in ddl.Items)
{
if (li.Text == filter["Year 1"].ToString().Substring(2, filter["Year 1"].ToString().Length - 3))
{
li.Selected = true;
return;
}
}
}
}
}
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
DropDownList dd = (DropDownList)sender;
if (dd.SelectedItem.Text != "Please Select")
{
if (filter.ContainsKey("Year 1"))
{
filter["Year 1"] = "='" + dd.SelectedItem.Text + "'";
}
else
{
filter.Add("Year 1", "='" + dd.SelectedItem.Text + "'");
}
}
else
{
filter.Remove("Year 1");
}
ApplyGridFilter();
GridView1.PageIndex = 0;
}
我想知道是否有其他方法可以做到這一點?