I have a user control made of txtbox and drop downlist.The drop downlist is rendered if data is present otherwise txtbox is rendered. How do i write get{} and set{} methods for th user control for adding and retrieving data as well as for visible property.
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; }
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.