| public partial class TestWebControl : System.Web.UI.UserControl |
| { |
| private const string _LOADINGSOURCE = "/_controltemplates/TestWebControl.ascx"; |
| private const string _VIEWSTATEITEMID = "VIEWSTATEITEMID"; |
| private const string _DATASOURCECACHE = "_DATASORCECACHE"; |
| |
| private ICachingOperations _caching; |
| private ITelerikBehavior _telerikbehavior; |
| private ISearchBehavior _search; |
| |
| private RadGrid _gridViewContent; |
| private List<GridColumn> _columns; |
| |
| public List<GridColumn> Columns |
| { |
| get |
| { |
| return this._columns; |
| } |
| set |
| { |
| this._columns= value; |
| } |
| } |
| private string _lastchacheDependency; |
| |
| private string _chacheDependency; |
| |
| public string CacheDependency |
| { |
| get { return _chacheDependency; } |
| set { _chacheDependency = value; } |
| } |
| |
| public ISearchBehavior Search |
| { |
| get { return _search; } |
| set { _search = value; } |
| } |
| |
| private bool _enableSelectColumn = true; |
| |
| public bool EnableSelectColumn |
| { |
| get { return _enableSelectColumn ; } |
| set { _enableSelectColumn = value; } |
| } |
| |
| |
| public ITelerikBehavior Telerikbehavior |
| { |
| get |
| { |
| if (_telerikbehavior != null) |
| { return _telerikbehavior; } |
| else |
| { |
| this._telerikbehavior = new TestTelerikBehavior(); |
| return _telerikbehavior; |
| } |
| } |
| set |
| { |
| if (_telerikbehavior != null) |
| { |
| _telerikbehavior = value; |
| } |
| } |
| } |
| |
| public ICachingOperations Caching |
| { |
| get { |
| |
| if(_caching!=null) |
| {return _caching;} |
| |
| else |
| { |
| this._caching = new ControlToSession(this.ID); |
| return _caching; |
| } |
| } |
| set |
| { |
| if (value != null) |
| {_caching = value;} |
| } |
| } |
| |
| public static TestWebControl LoadFileContent(Page page) |
| { |
| return page.LoadControl(_LOADINGSOURCE) as FileContentWebControl; |
| } |
| |
| private int pageSize = 5; |
| /// <summary> |
| /// Gets or sets the number of items to show per page |
| /// </summary> |
| public int PageSize |
| { |
| get { return pageSize; } |
| set { pageSize = value; } |
| } |
| |
| //public void ResetColumns(List<GridColumn> columns) |
| //{ |
| |
| // |
| //} |
| |
| protected override void OnInit(EventArgs e) |
| { |
| base.OnInit(e); |
| |
| |
| |
| _gridViewContent = new RadGrid(); |
| _gridViewContent.AutoGenerateColumns = false; |
| _gridViewContent.Attributes.Add("Width", "80%"); |
| _gridViewContent.AllowPaging = true; |
| _gridViewContent.PageSize = this.PageSize; |
| _gridViewContent.AllowSorting = true; |
| _gridViewContent.AllowMultiRowSelection = true; |
| _gridViewContent.PagerStyle.Mode=GridPagerMode.NextPrev; |
| //_gridViewContent.ClientSettings.AllowDragToGroup = true; |
| _gridViewContent.ClientSettings.EnableRowHoverStyle = true; |
| _gridViewContent.ClientSettings.EnablePostBackOnRowClick = true; |
| //_gridViewContent.ClientSettings.Selecting.AllowRowSelect = true; |
| //_gridViewContent.ItemCreated += new GridItemEventHandler(_gridViewContent_ItemCreated); |
| _gridViewContent.Skin = this.Telerikbehavior.TelerikSkin; |
| //_gridViewContent.EnableViewState = false; |
| _gridViewContent.NeedDataSource+=new GridNeedDataSourceEventHandler(_gridViewContent_NeedDataSource); |
| } |
| |
| void _gridViewContent_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
| { |
| if (!string.IsNullOrEmpty(_chacheDependency) && Columns != null) |
| { |
| |
| DataTable datssource = getData(); |
| if (source != null && datssource.Rows.Count > 0) |
| { |
| |
| _gridViewContent.DataSource = datssource; |
| |
| } |
| else |
| { |
| _gridViewContent.DataSource = null; |
| } |
| } |
| else |
| { |
| _gridViewContent.DataSource = null; |
| } |
| } |
| |
| //void _gridViewContent_ItemCreated(object sender, GridItemEventArgs e) |
| //{ |
| |
| // if (e.Item is GridDataItem) |
| // { |
| // e.Item.PreRender += new EventHandler(Item_PreRender); |
| // } |
| //} |
| |
| //void Item_PreRender(object sender, EventArgs e) |
| //{ |
| // ((sender as GridDataItem)["CheckBoxTemplateColumn"].FindControl("IMGchbx") as CheckBox).Checked = (sender as GridDataItem).Selected; |
| //} |
| |
| protected void RadAjaxPanel1_Init(object sender, EventArgs e) |
| { |
| |
| } |
| |
| protected override void CreateChildControls() |
| { |
| base.CreateChildControls(); |
| string traceConst = _TRACECONST + "CreateChildControls()"; |
| ECSpand.Logging.Log.WriteDebug("Entering", traceConst); |
| |
| |
| if (Columns != null) |
| { |
| if (_enableSelectColumn ) |
| { |
| TESTCHBoxColumn columnun = new TESTCHBoxColumn(); |
| columnun.UniqueName = "CheckBoxTemplateColumn"; |
| _gridViewContent.MasterTableView.Columns.Add(columnun); |
| |
| } |
| |
| //_gridViewContent.Columns.Clear(); |
| Columns.ForEach(o => _gridViewContent.Columns.Add(o)); |
| } |
| |
| if (ViewState[_VIEWSTATEITEMID] != null) |
| _lastchacheDependency = (ViewState[_VIEWSTATEITEMID] as string); |
| |
| _panFilec.Controls.Add(_gridViewContent); |
| } |
| |
| protected override void OnPreRender(System.EventArgs e) |
| { |
| if (!string.IsNullOrEmpty(_chacheDependency) && Columns !=null) |
| { |
| DataTable source = getData(); |
| if (source !=null && source.Rows.Count > 0) |
| { |
| _gridViewContent.DataSource = source; |
| if (ItemChanged()) |
| { |
| _gridViewContent.Rebind(); |
| } |
| _panFilec.Visible = true; |
| } |
| else |
| { _gridViewContent.Rebind(); } |
| |
| ViewState[_VIEWSTATEITEMID] = this._chacheDependency; |
| } |
| else |
| { |
| _gridViewContent.Rebind(); |
| ViewState[_VIEWSTATEITEMID] = null; |
| } |
| |
| |
| } |
| |
| public void ResetGridView() |
| { |
| if (_gridViewContent != null) |
| { |
| //_gridViewContent.DataSource = null; |
| this._chacheDependency = null; |
| _gridViewContent.Rebind(); |
| _panFilec.Controls.Clear(); |
| _panFilec.Visible = false; |
| this.Caching.RemoveObjectFromSession(_DATASOURCECACHE); |
| } |
| } |
| |
| private DataTable getData() |
| { |
| |
| if (ItemChanged()&& Search!=null) |
| { |
| DataTable table = this.Search.PerformSearch(); |
| this.Caching.SaveObjectToSession(_DATASOURCECACHE, table); |
| return table; |
| } |
| |
| else |
| { |
| return this.Caching.GetObjectFromSession(_DATASOURCECACHE) as DataTable; |
| } |
| } |
| |
| |
| protected override void Render(HtmlTextWriter writer) |
| { |
| |
| _panFilec.RenderControl(writer); |
| |
| } |
| |
| /// <summary> |
| /// Checks, if a different item is displayed |
| /// </summary> |
| /// <returns></returns> |
| bool ItemChanged() |
| { |
| return !(_chacheDependency.CompareTo(_lastchacheDependency)==0); |
| } |
| |
| } |
| } |