internal override void RenderEditView(HtmlTextWriter writer, RowCell cell) { if (Table.m_GotData == false) // Data need to be recovered if CacheDatasourceStructure is active. { Table.GetData(true); } if (Identity || AllowEdit == false || (Grid.DisplayView == DisplayView.Grid && AllowEditInGrid == false)) { RenderLabelView(writer, cell); return; } if (string.IsNullOrEmpty(ValueColumn)) { throw new GridException( String.Format(Table.m_Grid.GetSystemMessage("SystemMessage_ForeignkeyNoValueColumn"), Title)); } StringBuilder s = new StringBuilder(string.Empty); switch (ForeignkeyType) { case ForeignkeyType.Select: case ForeignkeyType.SelectMenu: { StringBuilder eventScript = new StringBuilder(string.Empty); StringBuilder javascript = new StringBuilder(string.Empty); if (AutoPostback || string.IsNullOrEmpty(ConfirmMessage) == false) { eventScript = new StringBuilder(" onchange=\""); if (string.IsNullOrEmpty(ConfirmMessage) == false) { eventScript.AppendFormat(" if(wgconfirm('{0}',this,'{1}')) ", ConfirmMessage.Replace("'", "\\'"), Grid.DialogTitle.Replace("'", "\\'")); } string link = Grid.EnableCallBack && !ForcePostBack ? Asynchronous.GetCallbackEventReference(Grid, string.Format( "ElementPostBack!{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues), false, string.Empty, string.Empty) : Grid.Page.ClientScript.GetPostBackEventReference(Grid, string.Format( "ElementPostBack!{0}!{1}", ColumnId, cell.Row. PrimaryKeyValues)); eventScript.AppendFormat("{0}\"", link); } StringBuilder onblur = new StringBuilder(" onblur=\""); if (Grid.ColumnChangedColour != Color.Empty) { onblur.AppendFormat("isChanged(this,'{0}');", Grid.ColorToHtml(Grid.ColumnChangedColour)); } onblur.Append("\""); javascript.Append(onblur); s.AppendFormat("<select {0} class=\"wgeditfield wgselectbox {4}\" id=\"{1}\" name=\"{1}\" {2} {3}>", javascript, cell.CellClientId, eventScript, Attributes, CssClass); if (m_Foreignkeytype == ForeignkeyType.SelectMenu && (Grid.Scripts == null || !Grid.Scripts.DisableSelectMenu)) { if (SelectMenuWidth > 0) { Grid.AddClientScript(writer, string.Format( "$(document).ready(function() {{$('#{0}').selectmenu({{maxHeight: {2},style:'dropdown',width: {1}}});}});", cell.CellClientId, SelectMenuWidth, SelectMenuMaxHeight)); } else { Grid.AddClientScript(writer, string.Format( "$(document).ready(function() {{$('#{0}').selectmenu({{maxHeight: {1},style:'dropdown'}});}});", cell.CellClientId, SelectMenuMaxHeight)); } } if (Table.Rows.Count == 0 && NullText == null) { NullText = "No data available."; } if (NullText != null) { s.AppendFormat("<option value=\"{1}\">{0}</option>", NullText, string.Empty); } //CreateRows(Grid,tree,null,0); s.Append(CreateSelectRows(TreeParentId != null, null, 0, cell)); s.Append("</select>"); } break; case ForeignkeyType.Radiobuttons: m_IsFormElement = false; m_Rowcounter = RecordsPerRow; s.AppendFormat("<table class=\"wgradiobuttons {1}\"><tr><td>{0}</td></tr></table>", CreateRadioButtons((TreeParentId != null), null, 0, cell), CssClass); break; } if (string.IsNullOrEmpty(ToolTipInput) == false) { s = new StringBuilder(Tooltip.Add(s.ToString(), ToolTipInput)); } EditHtml(s.ToString(), writer, cell); }
internal override void RenderEditView(WebGridHtmlWriter writer, RowCell cell) { if (Identity || AllowEdit == false || (Grid.DisplayView == DisplayView.Grid && AllowEditInGrid == false)) { RenderLabelView(writer, cell); return; } string uniqueID = cell.CellClientId; GetColumnPostBackData(cell); if (IsHtml) { EditHtml( !Grid.IsDesignTime ? DrawHtml(uniqueID, writer, Grid, cell) : HttpUtility.HtmlEncode("<HTML EDITOR DESIGN TIME>"), writer, cell); return; } string s; string theValueToShow = DisplayText(cell); /*if(TheValueToShow == null) * TheValueToShow = Value;*/ if (IsUrl && string.IsNullOrEmpty(theValueToShow)) { theValueToShow = HTTPCONST; } StringBuilder cssstyle = new StringBuilder("style=\""); theValueToShow = HttpUtility.HtmlEncode(theValueToShow); string size = string.Empty; string type = "text"; StringBuilder javascript = new StringBuilder(string.Empty); if (WidthEditableColumn != Unit.Empty) { cssstyle.AppendFormat("width:{0}; ", WidthEditableColumn); } if (HeightEditableColumn != Unit.Empty) { cssstyle.AppendFormat("height:{0}; ", HeightEditableColumn); } if (MaxSize > 0) { size = string.Format("maxlength=\"{0}\" ", MaxSize); } if (IsPassword) { type = "password"; } StringBuilder onblur = new StringBuilder(" onblur=\""); if (Grid.InputHighLight != Color.Empty) { javascript.AppendFormat( " onfocus=\"this.accessKey = style.backgroundColor;style.backgroundColor='{0}';\"", Grid.ColorToHtml(Grid.InputHighLight)); onblur.Append("style.backgroundColor=this.accessKey;"); } if (Grid.ColumnChangedColour != Color.Empty) { onblur.AppendFormat("isChanged(this,'{0}');", Grid.ColorToHtml(Grid.ColumnChangedColour)); } if (AutoPostback) { onblur.Append("if(hasChanged(this))"); onblur.Append(Grid.EnableCallBack && !ForcePostBack ? Asynchronous.GetCallbackEventReference(Grid, string.Format("ElementPostBack!{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues), false, string.Empty, string.Empty) : Grid.Page.ClientScript.GetPostBackEventReference(Grid, string.Format( "ElementPostBack!{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues))); } onblur.Append("\""); javascript.Append(onblur); string mask = null; if (!DisableMaskedInput && GenerateColumnMask != null) { string maskId = string.Format("{0}_{1}", Grid.ID, ColumnId); if (!Grid.MaskedColumns.ContainsKey(maskId)) { Grid.MaskedColumns.Add(maskId, GenerateColumnMask); } mask = string.Format(" alt=\"{0}\"", maskId); } cssstyle.Append("\""); if (HeightEditableColumn == Unit.Empty) { s = string.Format( "<input {0} {1} {6}{7} type=\"{2}\" class=\"wgeditfield\" {3} value=\"{4}\" id=\"{5}\" name=\"{5}\"/>", javascript, cssstyle, type, size, theValueToShow, uniqueID, Attributes, mask); } else { s = string.Format( "<textarea rows=\"1\" cols=\"1\" {0} {1} class=\"wgeditfield\" id=\"{2}\" name=\"{3}\" {4}>", javascript, cssstyle, uniqueID, uniqueID, Attributes); if (theValueToShow != null) { s += theValueToShow; } s += "</textarea>"; } if (string.IsNullOrEmpty(ToolTipInput) == false) { s = Tooltip.Add(s, ToolTipInput); } EditHtml(s, writer, cell); }
// 2005.01.09 - jorn - String.Compare, string.Length // 2005.01.05 - Jorn - Added check to see if there actually is a checkbox on "previous page". // Need to add a hidden field since checkbox "returns null" both for unchecked and non-existing internal void RenderDetail(bool enabled, WebGridHtmlWriter writer, RowCell cell) { if (AllowEdit == false || (Grid.DisplayView == DisplayView.Grid && AllowEditInGrid == false)) { enabled = false; } string uniqueId = cell.CellClientId; string strValue = DisplayText(cell); const string checkedValue = TrueValue; const string uncheckedValue = FalseValue; StringBuilder sb; if (String.Compare(strValue, checkedValue, true) == 0 && CheckedAlias != null && enabled == false) { sb = new StringBuilder(CheckedAlias); } else if (String.Compare(strValue, uncheckedValue, true) == 0 && UncheckedAlias != null && enabled == false) { sb = new StringBuilder(UncheckedAlias); } else { string bitchecked = string.Empty; string bitEnabled = string.Empty; if (String.Compare(strValue, checkedValue, true) == 0) { bitchecked = " checked=\"checked\""; } if (enabled == false) { bitEnabled = " disabled=\"disabled\""; } StringBuilder javascript = new StringBuilder(string.Empty); StringBuilder onblur = new StringBuilder(" onblur=\""); if (Grid.InputHighLight != Color.Empty) { javascript.AppendFormat( " onfocus=\"this.accessKey = this.style.backgroundColor;this.style.backgroundColor='{0}';\"", Grid.ColorToHtml(Grid.InputHighLight)); onblur.Append("this.style.backgroundColor=this.accessKey;"); } if (Grid.ColumnChangedColour != Color.Empty) { onblur.AppendFormat("isChanged(this,'{0}');", Grid.ColorToHtml(Grid.ColumnChangedColour)); } onblur.Append("\""); if (AutoPostback || string.IsNullOrEmpty(ConfirmMessage) == false) { StringBuilder eventScript = new StringBuilder(" onclick=\""); if (string.IsNullOrEmpty(ConfirmMessage) == false) { eventScript.AppendFormat(" if(wgconfirm('{0}',this,'{1}')) ", ConfirmMessage.Replace("'", "\\'"), Grid.DialogTitle.Replace("'", "\\'")); } string link = Grid.EnableCallBack && !ForcePostBack?Asynchronous.GetCallbackEventReference(Grid, string.Format("ElementPostBack!{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues), false, string.Empty, string.Empty) : Grid.Page.ClientScript.GetPostBackEventReference(Grid, string.Format( "ElementPostBack!{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues)); eventScript.AppendFormat("{0}\"", link); javascript.Append(eventScript); } javascript.Append(onblur); sb = new StringBuilder( string.Format( "<input {0} type=\"checkbox\" {1} {2} {4} id=\"cb_{3}\" name=\"{3}\" value=\"1\"/>", javascript, bitchecked, bitEnabled, uniqueId, Attributes)); if (string.IsNullOrEmpty(m_Displaylabel) == false) { sb.AppendFormat( "<label class=\"wglabel\" id=\"label_{0}\" for=\"cb_{0}\">{1}</label>", uniqueId, m_Displaylabel); } if (enabled) { writer.Write("<input type=\"hidden\" id=\"{0}_cb\" name=\"{0}_cb\" value=\"{1}\" />", uniqueId, checkedValue); } } if (string.IsNullOrEmpty(ToolTipInput) == false) { sb = new StringBuilder(Tooltip.Add(sb.ToString(), ToolTipInput)); } EditHtml(sb.ToString(), writer, cell); }
internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell) { if (cell == null) { return; } switch (SystemColumnType) { case Enums.SystemColumn.PagerColumn: if (Grid.RecordCount > Grid.PageSize) { return; } cell.Row.m_Table.m_Grid.PagerSettings.SliderOperation = System.Web.UI.WebControls.Orientation.Vertical; writer.Write(cell.Row.m_Table.m_Grid.PagerSettings.GetPager); cell.Row.m_Table.m_Grid.PagerSettings.PagerType = PagerType.None; break; case Enums.SystemColumn.SelectColumn: writer.Write( SelectableRows.GetItemCheckbox(Grid, cell.Row.PrimaryKeyValues, string.Empty, Grid.ColorToHtml(Grid.SelectRowColor))); break; case Enums.SystemColumn.DeleteColumn: if (cell.Row.AllowDelete == false) { Visibility = Visibility.None; Title = null; } else { string strConfirmDelete = Grid.GetSystemMessage("ConfirmDelete"); if (Html == null) { writer.Write(Buttons.Anchor(Grid, " ", "RecordDeleteClick", new[] { cell.Row.PrimaryKeyValues }, strConfirmDelete, Grid.GetSystemMessage("DeleteRow"), "ui-icon ui-icon-trash", null, false)); } else { writer.Write( Buttons.TextButtonControl(Grid, Html, "RecordDeleteClick", new[] { cell.Row.PrimaryKeyValues }, null, strConfirmDelete)); } } break; case Enums.SystemColumn.SpacingColumn: WidthColumnHeaderTitle = System.Web.UI.WebControls.Unit.Empty; writer.Write(" "); break; case Enums.SystemColumn.CopyColumn: if (cell.Row.AllowCopy == false) { Visibility = Visibility.None; Title = null; } else { const string strConfirmCopy = null; if (Html == null) { writer.Write( Buttons.Anchor(Grid, " ", "RecordCopyClick", new[] { string.Empty, cell.Row.PrimaryKeyValues }, strConfirmCopy, Grid.GetSystemMessage("CopyRow"), "ui-icon ui-icon-copy", null, false)); } else { writer.Write( Buttons.TextButtonControl(Grid, Html, "RecordCopyClick", new[] { string.Empty, cell.Row.PrimaryKeyValues }, null, strConfirmCopy)); } } break; case Enums.SystemColumn.NewRecordColumn: if (Grid.AllowNew == false) { Visibility = Visibility.None; Title = null; } else { if (Html == null) { writer.Write( Buttons.TextButtonControl(Grid, Grid.GetSystemMessage("NewRecord"), "NewRecordClick", new string[] { }, Grid.GetSystemMessageClass("NewRecord", "wgnewrecord"))); } else { writer.Write( Buttons.TextButtonControl(Grid, Html, "NewRecordClick", new string[] { }, Grid.GetSystemMessageClass("NewRecord", "wgnewrecord"))); } } break; case Enums.SystemColumn.UpdateGridRecordsColumn: if (Grid.AllowUpdate == false) { Visibility = Visibility.None; Title = null; } else { if (Html == null) { writer.Write( Buttons.TextButtonControl(Grid, Grid.GetSystemMessage("UpdateRows"), "UpdateRowsClick", new string[] { }, Grid.GetSystemMessageClass("UpdateRows", "wgUpdateRows"))); } else { writer.Write( Buttons.TextButtonControl(Grid, Html, "UpdateRowsClick", new string[] { }, Grid.GetSystemMessageClass("UpdateRows", "wgUpdateRows"))); } } break; case Enums.SystemColumn.UpdateGridRecordColumn: if (Grid.AllowUpdate == false) { Visibility = Visibility.None; Title = null; } else { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); System.Web.UI.HtmlTextWriter textwriter = new System.Web.UI.HtmlTextWriter(sw); if (Html == null) { textwriter.Write(Buttons.TextButtonControl(Grid, Grid.GetSystemMessage("UpdateRow"), "UpdateRowClick", new[] { cell.Row.PrimaryKeyValues }, Grid.GetSystemMessageClass("UpdateRow", "wgUpdateRow"))); } else { textwriter.Write(Buttons.TextButtonControl(Grid, Html, "UpdateRowClick", new[] { cell.Row.PrimaryKeyValues }, Grid.GetSystemMessageClass("UpdateRow", "wgUpdateRow"))); } writer.Write(sb); } break; } // base.RenderLabelView(writer,cell); RenderGrid(null, writer, cell); }
internal override void RenderEditView(WebGridHtmlWriter writer, RowCell cell) { if (AllowEdit == false || (Grid.DisplayView == DisplayView.Grid && AllowEditInGrid == false) || !Grid.GotHttpContext) { RenderLabelView(writer, cell); return; } StringBuilder s = new StringBuilder(string.Empty); StringBuilder javascript = new StringBuilder(string.Empty); s.Append(FileSource(false, cell)); StringBuilder onblur = new StringBuilder(" onblur=\""); if (Grid.InputHighLight != Color.Empty) { javascript.AppendFormat( " onfocus=\"accessKey = style.backgroundColor;style.backgroundColor='{0}';\"", Grid.ColorToHtml(Grid.InputHighLight)); onblur.Append("style.backgroundColor=accessKey;"); } if (Grid.ColumnChangedColour != Color.Empty) { onblur.AppendFormat("isChanged(this,'{0}');", Grid.ColorToHtml(Grid.ColumnChangedColour)); } onblur.Append("\""); javascript.Append(onblur); s.AppendFormat("<br/><input {0} {2} type=\"file\" class=\"wgeditfield\" name=\"{1}\" id=\"{1}\"/>", javascript, cell.CellClientId, Attributes); if (AllowEmpty && Required == false && Grid.InternalId != null && ((cell.Value != null) || (FileNameColumn != null && (cell.Value != null)))) { s.AppendFormat( "<br/><input class=\"wglinkfield\" name=\"{0}_delete\" id=\"{0}_delete\" value=\"TRUE\" type=\"checkbox\" /><label class=\"wgnowrap wglabel\" id=\"label_{0}\" for=\"{0}_delete\">{1}</label>", cell.CellClientId, Grid.GetSystemMessage("RemoveImage")); } if (Grid.FindForm != null) { if (Grid.EnableCallBack) { if (Grid.FindForm.Enctype.Equals("multipart/form-data", StringComparison.OrdinalIgnoreCase) == false) { Manager.AddScriptForClientSideEval(string.Format("document.getElementById(\"{0}\").encoding = \"multipart/form-data\";", Grid.FindForm.ClientID)); } } else { Grid.FindForm.Enctype = "multipart/form-data"; } } else { throw new GridException( string.Format("HtmlForm is not found for grid '{0}' and column '{1}'", Grid.ID, ColumnId)); } if (string.IsNullOrEmpty(ToolTipInput) == false) { s = new StringBuilder(Tooltip.Add(s.ToString(), ToolTipInput)); } EditHtml(s.ToString(), writer, cell); }
// 2005.01.19 - jorn, added this recursive function. private void RenderDetailTree(StringBuilder sb, string parentID, int level, RowCell cell) { if (parentID == null) { parentID = string.Empty; } List <string> selectedItems = new List <string>(); if (cell.Value != null && Grid.Page != null && Grid.Page.IsPostBack) { selectedItems.InsertRange(0, cell.Value.ToString().Split(',')); } for (int i = 0; i < Items.Count; i++) { if ((Items[i].ParentId ?? string.Empty) != parentID) { continue; } if (Grid.Page != null && Grid.Page.IsPostBack && selectedItems.Count > 0) { Items[i].Checked = selectedItems.Contains(Items[i].Value); } StringBuilder indentText = new StringBuilder(string.Empty); if (level > 0) { for (int j = 0; j < level; j++) { indentText.Append(TreeIndentText); } } StringBuilder selected = new StringBuilder(string.Empty); if (Items[i].Checked) { selected.Append(ManyToManyType == ManyToManyType.Multiselect ? " selected=\"selected\" " : " checked=\"checked\" "); } if (AllowEdit == false) { selected.Append(" disabled=\"disabled\" "); } if (ManyToManyType == ManyToManyType.Multiselect) { sb.AppendFormat("<option {0} value=\"{1}\">{2}{3}</option>", selected, Items[i].Value, indentText, Items[i].DisplayText); } else { if (i != 0) { if (m_Rowcounter == 0) { sb.Append("</tr><tr><td>"); m_Rowcounter = RecordsPerRow; } else { sb.Append("<td>"); } } m_Rowcounter--; sb.Append(indentText); StringBuilder javascript = new StringBuilder(string.Empty); StringBuilder onblur = new StringBuilder(" onblur=\""); if (Grid.InputHighLight != Color.Empty) { javascript.AppendFormat( " onfocus=\"this.accessKey = this.style.backgroundColor;this.style.backgroundColor='{0}';\"", Grid.ColorToHtml(Grid.InputHighLight)); onblur.Append("this.style.backgroundColor=this.accessKey;"); } if (Grid.ColumnChangedColour != Color.Empty) { onblur.AppendFormat("isChanged(this,'{0}');", Grid.ColorToHtml(Grid.ColumnChangedColour)); } onblur.Append("\""); javascript.Append(onblur); if ((AutoPostback || !string.IsNullOrEmpty(ConfirmMessage)) && Grid.Page != null) { StringBuilder eventScript = new StringBuilder(" onclick=\""); if (!string.IsNullOrEmpty(ConfirmMessage)) { eventScript.AppendFormat(" if(wgconfirm('{0}',this),'{1}') ", ConfirmMessage.Replace("'", "\\'"), Grid.DialogTitle.Replace("'", "\\'")); } string link = Grid.EnableCallBack && !ForcePostBack ? Asynchronous.GetCallbackEventReference(Grid, string.Format( "ElementPostBack!{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues), false, string.Empty, string.Empty) : Grid.Page.ClientScript.GetPostBackEventReference(Grid, string.Format( "ElementPostBack!{0}!{1}", ColumnId, cell.Row. PrimaryKeyValues)); eventScript.AppendFormat("{0}\"{1}", link, eventScript); javascript.Append(eventScript); } if (!string.IsNullOrEmpty(CheckedAlias) && Items[i].Checked) { sb.Append(CheckedAlias); sb.Append(Items[i].DisplayText); } else if (!string.IsNullOrEmpty(UncheckedAlias) && !Items[i].Checked) { sb.Append(UncheckedAlias); sb.Append(Items[i].DisplayText); } else { sb.AppendFormat( "<input {0} type=\"checkbox\" id=\"cb_{1}_{2}\" name=\"{1}\" value=\"{2}\" {3} />", javascript, cell.CellClientId, Items[i].Value, selected); sb.AppendFormat( "<label class=\"wglabel\" id=\"label_{0}_{1}\" for=\"cb_{0}_{1}\">", cell.CellClientId, Items[i].Value); sb.AppendFormat("{0}</label>", Items[i].DisplayText); } sb.Append("</td>"); } RenderDetailTree(sb, Items[i].Value, level + 1, cell); } }