2013-05-29 136 views
0

我有一個由txtbox和下拉列表組成的用戶控件。如果存在數據,則呈現下拉列表,否則顯示txtbox。我如何爲用戶控件編寫get {}和set {}方法來添加和檢索數據以及可見屬性。用戶控件asp.net

+0

dropdownlist如何獲取數據? – whiteElephant

+0

我有一個屬性在我的用戶控件中,從數組中填充ddl – user2381733

回答

0
partial class MyControl : UserControl 
{ 
    public bool VisibleInner { 
    get { return Panel1.Visible; } 
    set { Panel1.Visible = value ; } 
    } 

    private List<ControlData> _controlData; 
    public List<ControlData> ControlData { 
    get { return _controlData; } 
    set { _controlData = value; } 
    } 

    protected void Page_Load(object s, EventArgs e) 
    { 
    if (_controlData != null && _controlData.Count > 0) 
    { 
     TextBox1.Visible = false; 
     DropDownList1.Visible = true; 
     DropDownList1.DataSource = _controlData; 
     DropDownList1.DataBind(); 
    } 
    else 
    { 
     TextBox1.Visible = true; 
     DropDownList1.Visible = false; 
    } 
    } 
} 
public class ControlData 
{ 
    public string Value { get; set; } 
    public string Text { get; set; } 
}