Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Collections;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace Testing
- {
- public class EnhancedCheckboxList : System.Web.UI.WebControls.CheckBoxList
- {
- public string DataEnabledField
- {
- get
- {
- string s = (string)ViewState["DataEnabledField"];
- return (s == null) ? String.Empty : s;
- }
- set
- {
- ViewState["DataEnabledField"] = value;
- if (Initialized)
- OnDataPropertyChanged();
- }
- }
- public string DataCheckedField
- {
- get
- {
- string s = (string)ViewState["DataCheckedField"];
- return (s == null) ? String.Empty : s;
- }
- set
- {
- ViewState["DataCheckedField"] = value;
- if (Initialized)
- OnDataPropertyChanged();
- }
- }
- protected override void PerformDataBinding(IEnumerable dataSource)
- {
- if (dataSource != null)
- {
- bool hasSelectedField = DataCheckedField.Length != 0;
- bool hasEnabledField = DataEnabledField.Length != 0;
- if (!this.AppendDataBoundItems)
- this.Items.Clear();
- if (dataSource is ICollection)
- this.Items.Capacity = (dataSource as ICollection).Count + this.Items.Count;
- foreach (object dataItem in dataSource)
- {
- ListItem item = new ListItem()
- {
- Text = DataBinder.GetPropertyValue(dataItem, DataTextField).ToString(),
- Value = DataBinder.GetPropertyValue(dataItem, DataValueField).ToString(),
- Selected = hasSelectedField ? (bool)DataBinder.GetPropertyValue(dataItem, DataCheckedField) : false,
- Enabled = hasEnabledField ? (bool)DataBinder.GetPropertyValue(dataItem, DataEnabledField) : true
- };
- this.Items.Add(item);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement