DataTextField="c1_name" DataValueField="id">
DataValueField="id" onselectedindexchanged="c2_id_SelectedIndexChanged" AutoPostBack="True">
DataValueField="id" onselectedindexchanged="c3_id_SelectedIndexChanged">
后台:
private ProductClassService service = new ProductClassService();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
UserDataBind();
c1_id_SelectedIndexChanged(sender, e);
}
}
//绑定一级分类
private void UserDataBind()
{
c1_id.DataSource = service.getPClassList1();
c1_id.DataBind();
}
//绑定二级分类
protected void c1_id_SelectedIndexChanged(object sender, EventArgs e)
{
string id = c1_id.SelectedValue;
c2_id.DataSource = service.getPClassList2(id);
c2_id.DataBind();
c2_id_SelectedIndexChanged(sender,e);
}
//绑定三级分类
protected void c2_id_SelectedIndexChanged(object sender, EventArgs e)
{
string id = c2_id.SelectedValue;
IList
list = service.getPClassList3(id);
c3_id.DataSource = list;
c3_id.DataBind();
if (service.getPClassList3(id).Count <= 0)
{
ListItem item = new ListItem("没有选择", "0");
c3_id.Items.Insert(0, item);
}
c3_id_SelectedIndexChanged(sender, e);
}
//绑定四级分类
protected void c3_id_SelectedIndexChanged(object sender, EventArgs e)
{
string id = c3_id.SelectedValue;
IList list = service.getPClassList4(id);
c4_id.DataSource = list;
c4_id.DataBind();
if (list.Count <= 0)
{
ListItem item = new ListItem("没有选择", "0");
c4_id.Items.Insert(0, item);
}
}
http://blog.csdn.net/wengman/article/details/4095913
----------------------------------------------------------------
注意:
asp:DropDownList控件触发OnSelectedIndexChanged,AutoPostBack="true" 必须设置
设置默认值
ListItem item = new ListItem("请选择", "0");
this.DropDownList1.Items.Insert(0, item);
阅读(227) | 评论(0) | 转发(0) |