.

dynamic controls

The skeleton for a dynamic user control


public class MyCtrl : Control { List<T> items = null; protected override void OnLoad(EventArgs e) { if (this.Items.Count == 0) { LoadDataForControls(); } CreateControls(); base.OnLoad(e); } private void LoadDataForControls() { //load the data e.g. IDataReader dataReader = DataAccess.GetDataReader(Parameters); items = new List<T>(); { while (dataReader.Read()) { T bo = (T)(instance as BusinessObject).CreateFromReader(dataReader); items.Add(bo); } } } string _value = ""; public string Value { get { if (_value == "") { object o = ViewState["value"]; if (o != null) _value = (string)o; } return _value; } set { _value = value; ViewState["value"] = value; //update control rendered to display value ctrl.txt = .... } } protected void ctrltxt_changed(object sender, EventArgs e) { //update value value = ctrl.txt ... } }

What's your thoughts on this?

*

Protected by WP Anti Spam