日期:2014-05-17  浏览次数:20392 次

asp.net 如何在内容页面初始化的时候获得该内容页面中用户控件中DropDownList选定的值
public partial class Company : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }

    public void Bind() 
    {
        ClassCom c = new ClassCom();
        List<ClassCom> ClassComItems = new List<ClassCom>()
        {
            new ClassCom{CID=1,CName="小一"},
            new ClassCom{CID=2,CName="小二"},
            new ClassCom{CID=3,CName="小三"},
            new ClassCom{CID=4,CName="小四"}
        };

        this.DropDownList_Company.DataSource = ClassComItems;
        this.DropDownList_Company.DataTextField = "CName";
        this.DropDownList_Company.DataValueField = "CID";
        this.DropDownList_Company.DataBind();

        this.SelectValue = this.DropDownList_Company.SelectedValue;
    }

    [Category("数据绑定")]
    private string _SelectValue;

    public string SelectValue
    {
        get { return _SelectValue; }
        set { _SelectValue = value; }
    }
}

              
ASP.NET DropDownList 控件