Chinaunix首页 | 论坛 | 博客
  • 博客访问: 83800
  • 博文数量: 64
  • 博客积分: 1545
  • 博客等级: 上尉
  • 技术积分: 392
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-23 15:23
文章分类

全部博文(64)

文章存档

2013年(1)

2012年(63)

我的朋友

分类: 嵌入式

2012-11-03 22:18:13

                        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) |
给主人留下些什么吧!~~