/// <summary> /// Generate the image in the render methed /// Rely on base class for rendering, set the imageurl here so /// that generated ImageURL does not interfere with programatically set imageurl /// </summary> /// <param name="writer"></param> protected override void Render(HtmlTextWriter writer) { if (_imageType == DynamicImageType.External) { this.ImageUrl = Source; } else if (_imageType == DynamicImageType.Static) { this.ImageUrl = CalculateStaticImageUrl(); } else if (_imageType == DynamicImageType.Database) { if (string.IsNullOrEmpty(EntityId) || EntityId == "0") { this.ImageUrl = CalculateStaticImageUrl(); } else { this.ImageUrl = CalculateDatabaseImageUrl(); } } else { //throw new Exception("Unimplemented dynamic image type"); throw new HEMessageException(MR.GetMessage(MessageId.UnimplementedImageType)); } base.Render(writer); }
// override to create repeated items protected override void CreateChildControls() { if (!Visible) { return; } SelectedIndex = -1; object o = ViewStateAttributes.GetFromViewState("NumItems", null); if (o != null) { // get item ids and indexes for supporting ajax list append, insert and remove operations and restoring the exact previous state ArrayList itemIds = GetViewStateItemIds(); ArrayList itemIndexes = GetViewStateItemIndexes(); // clear any existing child controls Controls.Clear(); int numItems = (int)o; int pageSize = this.PageSize; for (int i = 0; i < numItems && i < pageSize; i++) { // create item RepeaterItem item = new RepeaterItem(i, null); InvisibleItem invItem = new InvisibleItem(i, null); try { // initialize item id if (itemIds != null) { item.ID = Iterator.FormatId((int)itemIds[i * 2]); invItem.ID = Iterator.FormatId((int)itemIds[i * 2 + 1]); } else { item.ID = Iterator.FormatId(i * 2); invItem.ID = Iterator.FormatId(i * 2 + 1); } // initialize item index if (itemIndexes != null) { item.ItemIndex = (int)itemIndexes[i * 2]; invItem.ItemIndex = (int)itemIndexes[i * 2 + 1]; } } catch (ArgumentOutOfRangeException) { throw new HEMessageException(MR.GetMessage(MessageId.AjaxListModified, "List Records", this.ID)); } // initialize item from template ItemTemplate.InstantiateIn(item); InvisibleTemplate.InstantiateIn(invItem); // add item to the child controls collection Controls.Add(item); Controls.Add(invItem); } } }
protected override bool OnBubbleEvent(object source, EventArgs e) { // set the selected index if (e is DataGridCommandEventArgs) { SelectedIndex = ((DataGridCommandEventArgs)e).Item.ItemIndex; } else if (e is AjaxEventArgs) { // ajax bubble up event // find the datagriditem that is parent of the sender control to set the selected index Control ctrl = source as Control; while (!(ctrl is DataGridItem)) { ctrl = ctrl.Parent; } SelectedIndex = ((DataGridItem)ctrl).ItemIndex; // create a datagrid command ajax event args instance, so that it can be trapped onbubble up by the table records select handler e = new DataGridCommandAjaxEventArgs((DataGridItem)ctrl, (Control)source, (AjaxEventArgs)e); } // set the datasource position so that the current record is set if the list is not empty and in memory IOSList rl = DataSource; if (rl != null && rl.Length > 0 && SelectedIndex != -1) { try { rl.SetPosition(SelectedIndex); } catch (ArgumentOutOfRangeException) { throw new HEMessageException(MR.GetMessage(MessageId.AjaxListModified, "Table Records", this.ID)); } } // keep the current row number of the record list before bubbling up the event int beforeBubbleCurrentRowNumber = (rl != null) ? rl.CurrentRowNumber : 0; // follow up the event bool ret = base.OnBubbleEvent(source, e); // store viewstate changes for the current row. Skip if: // - the record list is empty // - the current row number is not the same as the one before bubbling up event - happens when the list is iterated inside the action if (ret && rl != null && (rl.Length > 0) && (SelectedIndex != -1) && (beforeBubbleCurrentRowNumber == rl.CurrentRowNumber)) { SetViewStateStorage(rl.Current, SelectedIndex); } return(ret); }
public static OSDataGridTable FromTable(OSDataGrid parent, System.Web.UI.WebControls.Table table, ArrayList rowIds, ArrayList itemIndexes) { OSDataGridTable osTable = new OSDataGridTable(parent.ClientID); // copy everything from table // Properties osTable.BackImageUrl = table.BackImageUrl; osTable.Caption = table.Caption; osTable.CaptionAlign = table.CaptionAlign; osTable.CellPadding = table.CellPadding; osTable.CellSpacing = table.CellSpacing; osTable.GridLines = table.GridLines; osTable.HorizontalAlign = table.HorizontalAlign; // Rows TableRow[] tableRows = new TableRow[table.Rows.Count]; table.Rows.CopyTo(tableRows, 0); int i = 0; foreach (OSDataGridItem row in tableRows) { try { // restore the original id of this row, if set if (rowIds != null) { row.ID = OSDataGridItem.FormatId((int)rowIds[i], parent.EnableLegacyRendering); } else { row.ID = OSDataGridItem.FormatId(i + 1, parent.EnableLegacyRendering); } // set the item index, if set if (itemIndexes != null) { row.SetItemIndex((int)itemIndexes[i]); } } catch (ArgumentOutOfRangeException) { throw new HEMessageException(MR.GetMessage(MessageId.AjaxListModified, "Table Records", parent.ClientID)); } osTable.Rows.Add(row); i++; } return(osTable); }
protected override bool OnBubbleEvent(object sender, EventArgs args) { if (_itemCommandName == null) { return(true); } if (((sender.GetType() == typeof(Button) || sender.GetType() == typeof(LinkButton)) && (args is CommandEventArgs)) || args is AjaxEventArgs) { // Get the method Control ParentPage = Utils.GetOwnerOfControl(this); MethodInfo info = ParentPage.GetType().GetMethod(_itemCommandName); if (info == null) { throw (new Exception("Could not find method " + _itemCommandName)); } // Get the item that was clicked Control ctrl = (Control)sender; while (ctrl.GetType() != typeof(RepeaterItem)) { ctrl = ctrl.Parent; } // Set selected item index SelectedIndex = ((RepeaterItem)ctrl).ItemIndex; // set the datasource position so that the current record is set if the list is not empty and in memory IOSList rl = DataSource; if (rl != null && rl.Length > 0) { try { rl.SetPosition(SelectedIndex); } catch (ArgumentOutOfRangeException) { throw new HEMessageException(MR.GetMessage(MessageId.AjaxListModified, "List Records", this.ID)); } } // keep the current row number of the record list before bubbling up the event int beforeBubbleCurrentRowNumber = (rl != null) ? rl.CurrentRowNumber : 0; try { IteratorCommandEventArgs iteratorArgs; if (args is AjaxEventArgs) { // ajax event, must create IteratorCommandAjaxEventArgs to be trapped by the select handler of the iterator iteratorArgs = new IteratorCommandAjaxEventArgs(SelectedIndex, (Control)sender, (AjaxEventArgs)args); } else { // submit event, use IteratorCommandEventArgs iteratorArgs = new IteratorCommandEventArgs(SelectedIndex, (Control)sender); } // invoke the select method info.Invoke(ParentPage, new object[] { this, iteratorArgs }); } catch (Exception exception) { var exceptionAux = exception; while (exceptionAux != null && exception.GetType() == typeof(System.Reflection.TargetInvocationException)) { exceptionAux = exceptionAux.InnerException; } if (exceptionAux.GetType() == typeof(System.Threading.ThreadAbortException)) { return(true); } throw; } // store viewstate changes for the current row. Skip if: // - the record list is empty // - the current row number is not the same as the one before bubbling up event - happens when the list is iterated inside the action if (rl != null && rl.Length > 0 && SelectedIndex != -1 && beforeBubbleCurrentRowNumber == rl.CurrentRowNumber) { SetViewStateStorage(rl.Current, SelectedIndex); } return(true); } return(true); }