I want to use a column of webgrid as control WebDatePicker. It's easy for user to select the correct date by clicking this control. I used this with netadvantage 2007 vol1. It worked easily. Now with 2010 vol 1 i have this error :
could you help me to solve this problem step by step. I will be happy if you have an example for me.
Hi,
The WebDatePicker is AJAX control which is located in different dll and does not use shared.dll, where IProvidesEmbeddableEditor is located. It is possible to implement custom embeddable editor for UltraWebGrid, though, besides implementation of server interface members, it also assume several specific members in javascript object of editor. I wrote a sample for you, which implements most features, though, it may have side effects and is not able to do full job, like processing first key, ocasional closing calendar on start, etc. It also uses few internal methods in javascript, which are not supported and in case of misbehavior, exceptions or side effects, that sample should not be used.You should include aps:ScriptManager in webform and implement following server and javascript methods.
aspx.cs codes:
private MyWebDatePicker _MyWebDatePicker; protected override void OnInit(EventArgs e) { base.OnInit(e); this.UltraWebGrid1.InitializeDataSource += new Infragistics.WebUI.UltraWebGrid.InitializeDataSourceEventHandler(UltraWebGrid1_InitializeDataSource); this._MyWebDatePicker = new MyWebDatePicker(); this._MyWebDatePicker.ID = "_MyWebDatePicker1"; this._MyWebDatePicker.ClientSideEvents.Initialize = "WebDatePicker1_Initialize"; this.Form.Controls.Add(this._MyWebDatePicker); } void UltraWebGrid1_InitializeDataSource(object sender, Infragistics.WebUI.UltraWebGrid.UltraGridEventArgs e) { DataTable dt = new DataTable("Customer"); dt.Columns.Add("CustomerID", typeof(int)); dt.Columns.Add("CustomerName", typeof(string)); dt.Columns.Add("Address", typeof(string)); dt.Columns.Add("DateOfJoin", typeof(DateTime)); dt.Rows.Add(new object[] { 1, "John Lever", "South Street", DateTime.MinValue }); dt.Rows.Add(new object[] { 2, "Walter Smith", "12/4 S MarkD", new DateTime(2009, 10, 20) }); dt.Rows.Add(new object[] { 3, "Kathy Lever", "23/45 Honai", DateTime.Now }); dt.Rows.Add(new object[] { 4, "George Wills", "233 Walter Street", DateTime.Now }); this.UltraWebGrid1.DataSource = dt; } protected void UltraWebGrid1_InitializeLayout(object sender, Infragistics.WebUI.UltraWebGrid.LayoutEventArgs e) { this.UltraWebGrid1.Columns[3].EditorControlID = this._MyWebDatePicker.UniqueID; this.UltraWebGrid1.Columns[3].Type = Infragistics.WebUI.UltraWebGrid.ColumnType.Custom; }}internal class MyWebDatePicker : Infragistics.Web.UI.EditorControls.WebDatePicker, Infragistics.WebUI.Shared.IProvidesEmbeddableEditor{ string Infragistics.WebUI.Shared.IProvidesEmbeddableEditor.EditorID {get{return this.ID;}} string Infragistics.WebUI.Shared.IProvidesEmbeddableEditor.EditorClientID {get{return this.ClientID;}} bool Infragistics.WebUI.Shared.IProvidesEmbeddableEditor.CanEditType(System.Type type) {return type != null && type.Equals(typeof(DateTime));} bool Infragistics.WebUI.Shared.IProvidesEmbeddableEditor.CanRenderType(System.Type type) {return type != null && type.Equals(typeof(DateTime));} string Infragistics.WebUI.Shared.IProvidesEmbeddableEditor.RenderValue(object value) { if((value is string) && ((string)value).Length > 1) return (string)value; if(!(value is DateTime) || DateTime.MinValue.Equals(value)) return string.Empty; string format = this.DisplayModeFormat; if(format.Length == 0) format = this.EditModeFormat; return ((DateTime)value).ToString(format, this.Culture); }}
aspx:
<script type="text/javascript">function WebDatePicker1_Initialize(editor){ var elem = editor.get_element(); elem.Object = editor; editor.Element = elem; editor.setValue = editor.set_value; editor.getValue = editor.get_value; editor._old_fireEvt = editor._fireEvt; editor._fireEvt = function(p1, evt, p3, p4) { editor._old_fireEvt(p1, evt, p3, p4); if(evt && (evt.keyCode == 27 || evt.keyCode == 13 || evt.type == 'blur')) { $util.cancelEvent(evt); igtbl_hideEdit(null, {event:evt}, editor._gridObj); } } editor.addEventListener = function(name, fn, g) { editor._gridObj = g; } editor.removeEventListener = function(name, fn) { editor._gridObj = null; } editor.getRenderedValue = function(v) { return editor._toTxt(v, false, ''); } editor.setVisible = function(show, x, y, width, height) { var style = elem.style; style.position = 'absolute'; if(show) { style.left = (x - 1) + 'px'; style.top = (y - 1) + 'px'; editor._fixSize(width + 'px', height + 'px'); editor.focus(); } $util.display(elem, !show); }}</script><asp:ScriptManager runat="server" ID="ScriptManager1"></asp:ScriptManager><igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" Height="121px" Width="371px" OnInitializeLayout="UltraWebGrid1_InitializeLayout"> <displaylayout allowupdatedefault="Yes"></displaylayout></igtbl:UltraWebGrid>
Viktor,
I am trying to upgrade from WebDateTimeEdit to WebDateTimeEditor and I get this error. What is a possible solution?
I assume that your application uses UltraWebGrid. That control alone with editors such as WebDateEdit, WebMaskEdit, etc belong to Infragistics.WebUI and those editors implement that interface and compatible with each other and with grid.
The WebDataGrid, WebDateTimeEditor, etc. belong to Infragistics.Web.UI and all controls in that dll are based on ajax architecture with ScriptManager, etc. features. Different controls from both packages may exist and work within the same page, though, if they depend on each other, then application will be broken. Better to say controls will fail in case of any async postback triggered by control from another package. The editors such WebDateTimeEditor does not implement IProvidesEmbeddableEditor, because it is not compatible with UltraWebGrid.
The WebDateTimeEdit can not be replaced by WebDateTimeEditor for cell editors of UltraWebGrid (or it will require a lot of codes, which can be unstable). In case of WebDateTimeEditor, application will need to add ScriptManager and all other quite heavy stuff related to AJAX.
If you have WebDateTimeEditor, then it means that you automatically have WebDataGrid. You may consider to replace old grid in your application by new one. New grid does support all editors including WebDateTimeEditor, WebDatePicker, WebSlider, WebRating, etc.