如何用两个dropdownlist控制gridview中显示的数据?
两个dropdownlist,一个是门类,一个是材料,两个dropdownlist的数据之间没有关系,用两个同时进行筛选时第二个不起作用,该怎么改?stringd_nam...
两个dropdownlist,一个是门类,一个是材料,两个dropdownlist的数据之间没有关系,用两个同时进行筛选时第二个不起作用,该怎么改?
string d_name;
string f_name;
ProductBLL pbll = new ProductBLL();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindProductGrid();
}
}
public void BindProductGrid() //GridView数据绑定
{
if (d_name!=null)
{
ProductGridView.DataSource = pbll.GetProductByDepartment(d_name);
ProductGridView.DataBind();
}
else if (f_name != null)
{
ProductGridView.DataSource = pbll.GetProductByFlower(f_name);
ProductGridView.DataBind();
}
else
{
ProductGridView.DataSource = pbll.GetProduct();
ProductGridView.DataBind();
}
}
protected void DepartmentList_SelectedIndexChanged(object sender, EventArgs e)
{
d_name = DepartmentList.SelectedItem.ToString();
BindProductGrid();
}
protected void FlowerList_SelectedIndexChanged(object sender, EventArgs e)
{
f_name = FlowerList.SelectedItem.ToString();
BindProductGrid();
} 展开
string d_name;
string f_name;
ProductBLL pbll = new ProductBLL();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindProductGrid();
}
}
public void BindProductGrid() //GridView数据绑定
{
if (d_name!=null)
{
ProductGridView.DataSource = pbll.GetProductByDepartment(d_name);
ProductGridView.DataBind();
}
else if (f_name != null)
{
ProductGridView.DataSource = pbll.GetProductByFlower(f_name);
ProductGridView.DataBind();
}
else
{
ProductGridView.DataSource = pbll.GetProduct();
ProductGridView.DataBind();
}
}
protected void DepartmentList_SelectedIndexChanged(object sender, EventArgs e)
{
d_name = DepartmentList.SelectedItem.ToString();
BindProductGrid();
}
protected void FlowerList_SelectedIndexChanged(object sender, EventArgs e)
{
f_name = FlowerList.SelectedItem.ToString();
BindProductGrid();
} 展开
展开全部
pbll.GetProduct(string d_name ,string f_name)
{
string con=""
if(d_name!=null && d_name!="")
con+=" and d_name='"+d_name+"'';
if(f_name!=null && f_name!="")
con+=" and f_name='"+f_name+"'";
string sql="select * from table where 1=1"+con;
//执行sql
}
public void BindProductGrid() //GridView数据绑定
{
ProductGridView.DataSource = pbll.GetProduct(DepartmentList.SelectedItem.ToString(),FlowerList.SelectedItem.ToString());
ProductGridView.DataBind();
}
}
protected void DepartmentList_SelectedIndexChanged(object sender, EventArgs e)
{
BindProductGrid();
}
protected void FlowerList_SelectedIndexChanged(object sender, EventArgs e)
{
BindProductGrid();
}
{
string con=""
if(d_name!=null && d_name!="")
con+=" and d_name='"+d_name+"'';
if(f_name!=null && f_name!="")
con+=" and f_name='"+f_name+"'";
string sql="select * from table where 1=1"+con;
//执行sql
}
public void BindProductGrid() //GridView数据绑定
{
ProductGridView.DataSource = pbll.GetProduct(DepartmentList.SelectedItem.ToString(),FlowerList.SelectedItem.ToString());
ProductGridView.DataBind();
}
}
protected void DepartmentList_SelectedIndexChanged(object sender, EventArgs e)
{
BindProductGrid();
}
protected void FlowerList_SelectedIndexChanged(object sender, EventArgs e)
{
BindProductGrid();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询