我确实有一个gridview,里面有3个下拉列表。 例如:如果网格视图有15行,则每行有3个下拉列表
1)使用第一个下拉列表的选定索引更改第一个下拉列表绑定第二个下拉列表
2)使用第二个下拉列表的选定索引更改的第二次下拉值绑定第三次下拉列表
那我怎么能实现呢?
答案 0 :(得分:0)
在级联下拉列表中将AutoPostBack
设置为true
。处理下拉列表中的SelectedIndexChanged
事件。将GridView
本身数据绑定不在回发上非常重要,因此请使用IsPostBack
属性。否则事件不会被触发。
protected void Ddl1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl1 = (DropDownList)sender;
GridViewRow row = (GridViewRow)ddl1.NamingContainer;
DropDownList ddl2 = (DropDownList)row.FindControl("DropDownList2ID");
// here get the datasource for ddl2 according to ddl1.SelectedValue
ddl2.DataSource = GetDataSource(ddl1.SelectedValue);
ddl2.DataBind();
}
protected void Ddl2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl2 = (DropDownList)sender;
GridViewRow row = (GridViewRow)ddl2.NamingContainer;
DropDownList ddl3 = (DropDownList)row.FindControl("DropDownList3ID");
// here get the datasource for ddl3 according to ddl1.SelectedValue
ddl3.DataSource = GetDataSource(ddl2.SelectedValue);
ddl3.DataBind();
}