我有一个用户控件,控件中有一个DropDownList,当我加载这个控件的时候,我想让它一加载这个用户控件时,所选择的项的值等于一个String,这个要怎么做呢?

解决方案 »

  1.   


    这个DropDownList是在用户控件中的
      

  2.   

    this.DropDownList1.SelectedIndex = 0;
      

  3.   

    //在用户控件里面
    protected void Page_Load(object sender, EventArgs e)
        {
            this.DropDownList1.Items.Add("aaa");
            this.DropDownList1.Items.Add("bbb");        this.DropDownList1.SelectedValue = "bbb";
        }
      

  4.   

    可以公开一个属性
    private _SelectedValue;
    public string SelectedValue
    {
    get{}
    set{}
    }this.DropDownList1.SelectedValue = SelectedValue;在页面文件(aspx)里面给这个属性赋值:usercontrol1.SelectedValue="SelectedValue";