public override void DataBind() { if (_bound) { return; } _bound = true; _dataSrc = new EmptyDataSrc(); PagesManager pMgr = new PagesManager(); if (PageId != null) { var images = pMgr.GetPageImages(PageId.Value); this.Data = images; _dataSrc.RowsCount = images.Count(); _dataSrc.Data = this.Data; _dataSrc.HasData = _dataSrc.RowsCount > 0; } base.DataBind(); }
public override void DataBind() { if (bound) { return; } bound = true; int?itemId = null; object obj = ControlUtils.GetBoundedDataField(this.NamingContainer, "ItemId"); if (obj != null) { itemId = (int)obj; } if (itemId != null) { _dataSrc = new EmptyDataSrc(); SqlCommand cmd = DBUtils.StoredProcedure("[Shopping_GetRelatedProducts]", cte.lib); DBUtils.AddCommandParameter(cmd, "ItemId", SqlDbType.Int, itemId.Value, ParameterDirection.Input); DataTable dt = DBUtils.GetDataSet(cmd, cte.lib).Tables[0]; this.Data = dt; _dataSrc.RowsCount = dt.Rows.Count; _dataSrc.Data = this.Data; _dataSrc.HasData = _dataSrc.RowsCount > 0; } base.DataBind(); }
public override void DataBind() { if (_bound) { return; } _bound = true; _dataSrc = new EmptyDataSrc(); PhotoAlbumsManager pMgr = new PhotoAlbumsManager(); if (AlbumId != null) { DataView images = pMgr.GetImages(AlbumId.Value); this.Data = images; _dataSrc.RowsCount = images.Count; _dataSrc.Data = this.Data; _dataSrc.HasData = _dataSrc.RowsCount > 0; } base.DataBind(); }
/// <summary> /// Creates the data /// </summary> void getData() { if (DataSrc == null) { if (!Visible) { DataSrc = new EmptyDataSrc(); } else { // Connects to the database if (data == null) { if (!String.IsNullOrWhiteSpace(SelectCommand)) { if (enablePaging) { dataSrc = new PagingDataSource(selectCommand, _Page, OrderBy, DataLibrary); ((PagingDataSource)dataSrc).PageSize = PageSize; } else { dataSrc = new DataSource(selectCommand, OrderBy, DataLibrary); } try { data = dataSrc.GetData(); } catch (Exception ex) { ErrorContext.Add("CustomDataSource", ex); ErrorContext.Add("CustomDataSource-Select", SelectCommand); } checkEmptyValue((DataTable)data); } } // Use Config files if (data == null) { if (!String.IsNullOrWhiteSpace(configFile)) { DataSet ds = XmlManager.GetDataSet(configFile); if (ds != null && ds.Tables.Count > 0) { if (!String.IsNullOrWhiteSpace(configTable)) { data = ds.Tables[configTable]; } else { data = ds.Tables[0]; } if (!String.IsNullOrEmpty(OrderBy)) { data = new DataView((DataTable)data, "", OrderBy, DataViewRowState.CurrentRows); checkEmptyValue((DataView)data); } else { checkEmptyValue((DataTable)data); } } } } // Use an enum type if (data == null) { if (!String.IsNullOrWhiteSpace(enumType)) { string[] temp = enumType.Split(','); Assembly assem = Assembly.Load(temp[1]); Type typ = assem.GetType(temp[0]); FieldInfo[] fields = typ.GetFields(); DataTable table = new DataTable(); table.Columns.Add("Value"); table.Columns.Add("Name"); table.Columns.Add("NameAttribute"); table.Columns.Add("DescriptionAttribute"); table.Columns.Add("PermissionGroupAttribute"); checkEmptyValue(table); foreach (var field in fields) { if (field.Name.Equals("value__")) { continue; } DataRow row = table.NewRow(); row["Value"] = field.GetRawConstantValue(); row["Name"] = field.Name; row["NameAttribute"] = EnumHelper.GetName((Enum)Enum.Parse(typ, field.Name)); row["DescriptionAttribute"] = EnumHelper.GetDescription((Enum)Enum.Parse(typ, field.Name)); row["PermissionGroupAttribute"] = EnumHelper.GetPermissionGroup((Enum)Enum.Parse(typ, field.Name)); table.Rows.Add(row); } data = table; } } // Use Direct string input 1,2,3 if (data == null) { if (!String.IsNullOrWhiteSpace(dataString)) { string[] temp = dataString.Split(new Char[] { ',', ';', '|', '`' }); DataTable table = new DataTable(); table.Columns.Add("Value"); table.Columns.Add("Name"); checkEmptyValue(table); if (!String.IsNullOrWhiteSpace(DataStringValues)) { string[] valuesTemp = DataStringValues.Split(new char[] { ',', ';', '-', '`' }); try { if (valuesTemp.Length != temp.Length) { throw new Exception("DataString and DataStringValues must have equal amount of values"); } else { for (int i = 0; i < temp.Length; i++) { DataRow row = table.NewRow(); row["Value"] = valuesTemp[i]; row["Name"] = temp[i]; table.Rows.Add(row); data = table; } } } catch (Exception ex) { ErrorContext.Add("CustomDataSource", ex.Message); } } else { foreach (string str in temp) { DataRow row = table.NewRow(); row["Value"] = str; row["Name"] = str; table.Rows.Add(row); data = table; } } } } if (dataSrc == null && data != null) { EmptyDataSrc tempSrc = new EmptyDataSrc(); tempSrc.Data = data; if (data != null) { if (data as DataView != null) { tempSrc.RowsCount = ((DataView)data).Table.Rows.Count; } else { tempSrc.RowsCount = ((DataTable)data).Rows.Count; } tempSrc.HasData = tempSrc.RowsCount > 0; } dataSrc = tempSrc; } } } else { data = DataSrc.Data; } }
public override void DataBind() { if (_bound) { return; } _bound = true; CustomPage page = this.Page as CustomPage; DataTable cachedData = null; MemberList memberListParent = null; Object obj = page.PageContext[cte.MemberEducationContext]; _dataSrc = new EmptyDataSrc(); if (obj != null) { cachedData = obj as DataTable; } else { Control parent = this.Parent; while (parent != null) { memberListParent = parent as MemberList; if (memberListParent != null) { break; } parent = parent.Parent; } if (memberListParent != null) { DataTable existingList = memberListParent.Data as DataTable; if (existingList != null) { StringBuilder filter = new StringBuilder(); string sep = ""; foreach (DataRow member in existingList.Rows) { filter.Append(sep); filter.Append(member["MemberId"]); sep = ","; } cachedData = DBUtils.GetDataSet(String.Format("Select * from MemberEducationView where MemberId in ({0})", filter.ToString()), cte.lib).Tables[0]; } } } _dataSrc = new EmptyDataSrc(); int currentUser = (int)DataBinder.Eval(this.NamingContainer, "DataItem.MemberId"); if (cachedData != null) { this.Data = new DataView(cachedData, string.Format("MemberId={0}", currentUser), "UniversityName", DataViewRowState.CurrentRows); _dataSrc.RowsCount = cachedData.Rows.Count; } else { DataTable temp = DBUtils.GetDataSet(String.Format("Select * from MemberEducationView where MemberId = {0}", currentUser), cte.lib).Tables[0]; this.Data = temp; _dataSrc.RowsCount = temp.Rows.Count; } _dataSrc.Data = this.Data; _dataSrc.HasData = _dataSrc.RowsCount > 0; base.DataBind(); }