我有两个DropDownList:DropDownList1,DropDownList2,
有一表table(code,name)
DropDownList1用来装表table的code,DropDownList2用来name,
我的想法是当选择DropDownList2中的name时,保存的时候就是保存的DropDownList1的code这个字段。
DropDownList1我要隐藏的。
各位,这个怎么做呢?

解决方案 »

  1.   

    private void ddl1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
       if(ddl2.Items.FindByValue(this.ddl1.selectedvalue) != null)
          ddl2.Items.FindByValue(this.ddl1.selectedvalue).Selected = true;
    }
      

  2.   

    用当前记录的概念就可以了。其实你只要一个DropDownList2就可了,
    ((DataRowView)((CurrencyManager)this.BindingContext[this.dtLink].Current)).Row[code];
    就是你当前 选择的用户CODE。
      

  3.   

    不需要如此,DropDownList有一个DataTextField(即显示信息),和一个DataValueField, DropDownList.DataSource =ds.Tables[0].DefaultView;
             DropDownList.DataTextField="name";
    DropDownList.DataValueField="code";
    DropDownList.DataBind();
      

  4.   

    呵呵,eagle128(无心阁)的为正解,只用一个下拉列表就行了!!
      

  5.   

    在编写了前一个DropDownList控件的选择更改事件DropDownList1_SelectedIndexChanged后,还应该在其属性中将AutoPostback设置为true才行,这样才能在前一个DropDownList选项更改后执行更改事件,否则只能在页面重载时发生更改事件!