//private static Dictionary<Type, Action<object, object>> map; //static DataBindingHelper() //{ // map = new Dictionary<Type, Action<object, object>>(); // map.Add( // typeof(DataBoundControl), // (control, data) => // { // ((DataBoundControl)control).DataSource = data; // ((DataBoundControl)control).DataBind(); // }); // map.Add(typeof(BaseDataList), // (control, data) => // { // ((BaseDataList)control).DataSource = data; // ((BaseDataList)control).DataBind(); // }); //} public static void SetDataSourceAndBind(object control, object dataSource) { if (control is DataBoundControl) { DataBoundControl bindable = (DataBoundControl)control; bindable.DataSource = dataSource; bindable.DataBind(); } else if (control is BaseDataList) { BaseDataList bindable = (BaseDataList)control; bindable.DataSource = dataSource; bindable.DataBind(); } else if (control is Repeater) { Repeater bindable = (Repeater)control; bindable.DataSource = dataSource; bindable.DataBind(); } else { throw new NotSupportedException(control.GetType().Name + " is not a supported data control"); } //foreach (var type in map.Keys) //{ // if (type.IsAssignableFrom(control.GetType())) // { // map[type](control, dataSource); // return; // } //} //throw new NotSupportedException(control.GetType().Name + " is not a supported data control"); }
/// <summary> /// 分页数据绑定(列表控件和数据控件) /// </summary> /// <param name="ctrl"></param> /// <param name="source"></param> /// <param name="RecordCount"></param> /// <param name="pager"></param> public static void BindControl(DataBoundControl ctrl, object source, int RecordCount, AspNetPager pager) { ctrl.DataSource = source; ctrl.DataBind(); pager.RecordCount = RecordCount; pager.SetRewriteUrl(); }
public static void SetDataSourceAndBind(object control, object dataSource) { if (control is DataBoundControl) { DataBoundControl bindable = (DataBoundControl)control; bindable.DataSource = dataSource; bindable.DataBind(); } else if (control is BaseDataList) { BaseDataList bindable = (BaseDataList)control; bindable.DataSource = dataSource; bindable.DataBind(); } else if (control is Repeater) { Repeater bindable = (Repeater)control; bindable.DataSource = dataSource; bindable.DataBind(); } else { throw new NotSupportedException(control.GetType().Name + " is not a supported data control"); } }
public void CurrentBindData <T>(DataBoundControl objDataBoundControl, ObjectQuery <T> objObjectQuery) where T : EntityObject { int recordCount = 0; objDataBoundControl.DataSource = objObjectQuery.GetPage <T>(this.Condition, this.SortExpression, this.PageSize, this.PageIndex, out recordCount); this.RecordCount = recordCount; objDataBoundControl.DataBind(); }
public void CurrentBindData(DataBoundControl objDataBoundControl, ObjectQuery <DbDataRecord> objObjectQuery) { int recordCount = 0; objDataBoundControl.DataSource = objObjectQuery.GetPage <DbDataRecord>(this.Condition, this.SearchSortExpression(), this.PageSize, this.PageIndex, out recordCount); this.RecordCount = recordCount; objDataBoundControl.DataBind(); }
/// <summary> /// Raised when the news listview is rendered. Prevents from pagination problems. /// </summary> /// <param name="sender">Element which raised the event.</param> /// <param name="e">Event arguments</param> protected void listviewShows_PreRender(object sender, EventArgs e) { DataBoundControl control = (DataBoundControl)sender; if (control.Visible) { IEnumerable <Show> shows = _client.GetShows(); control.DataSource = shows; control.DataBind(); } }
/// <summary> /// 分页数据绑定(列表控件和数据控件) /// </summary> /// <param name="ctrl">绑定控件</param> /// <param name="source">数据源</param> /// <param name="pager">分页控件</param> public static void BindControl(DataBoundControl ctrl, DataSet source, AspNetPager pager) { if (source.Tables.Count < 1) { return; } ctrl.DataSource = source.Tables[0]; ctrl.DataBind(); pager.RecordCount = Convert.ToInt32(source.Tables[1].Rows[0][0]); pager.SetRewriteUrl(); }
public static void BindDataBoundControl(DataBoundControl ctrl, object dataSource) { ctrl.DataSource = dataSource; ctrl.DataBind(); }
internal static void ClearData(this DataBoundControl control) { control.DataSource = null; control.DataBind(); }
/// <summary> /// Binds the with. /// </summary> /// <param name="control">The control.</param> /// <param name="dataSource">The data source.</param> /// <createdOn>1/26/2016 9:58 AM</createdOn> public static void BindWith(this DataBoundControl control, ICollection dataSource) { control.DataSource = dataSource; control.DataBind(); }