Telerik Forums
UI for ASP.NET AJAX Forum
6 answers
387 views
Hi Telerik,

How to disable "previous & first page" arrow buttons on page 1 and "next & last page" arrows when on last page?
Also disabling all arrows when row count is less than the page size?

Appreciate your help. Thanks!
Bill
Top achievements
Rank 1
 answered on 25 Jan 2013
5 answers
283 views
I'm trying to use RadDatePicker in Visual Web Part. The problem was when I tried to call it in .vb (let's say its ID is radDate1), it did not exist in IntelliSense. Seeming like it's not recognized. 

TestWebPart.ascx

..
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
        <telerik:RadDatePicker ID="radDate1" Runat="server" AutoPostBack="false">                           
            <DateInput DateFormat="MM/dd/yyyy" />                   
        </telerik:RadDatePicker>
..

TestWebPart.ascx.vb

Private
Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
     radDate1  <--- not found in IntelliSense
End Sub

web.config
<SafeControls>
...
<SafeControl Assembly="Telerik.Web.UI, Version=2010.1.309.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Namespace="Telerik.Web.UI" TypeName="*" Safe="True" SafeAgainstScript="False" />
...
</SafeControls>
...
<assemblies>
...
<add assembly="Telerik.Web.UI, Version=2010.1.309.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" />
...
</assemblies>

Please advise

Thanks
Brew

Bob
Top achievements
Rank 1
 answered on 25 Jan 2013
2 answers
196 views
I have a dll project in that added the following methods to create RadGrid dynamically

this method will be called inside a ascx control to build the grid
If I use Telerik.Web.UI.dll 2012.2.607.40 version ItemCommand evant firing for InitInsert, PerformInsert, Update and Delete
But If I use Telerik.Web.UI, Version=2011.1.519.40 it is not firing all the events Only InitInsert is working
How to Solve this.

    #region CreateRadGrid

        public Control CreateRadGrid(BusinessProperty property, bool readOnly)
        {
            bool addEnabled = (property.Description.IndexOf("__MIADD__", StringComparison.Ordinal) != -1);
            bool editEnabled = (property.Description.IndexOf("__MIEDIT__", StringComparison.Ordinal) != -1);
            bool deleteEnabled = (property.Description.IndexOf("__MIDELETE__", StringComparison.Ordinal) != -1);

            if (readOnly)
            {
                addEnabled = false;
                editEnabled = false;
                deleteEnabled = false;
            }

            var divOuterControl = GetMIDivOuterControl(property);
            var panelTemplateControl = new PanelTemplateControl
            {
                TemplateTitle = property.Caption + ((property.Description.IndexOf("__OFFICE_USE__", System.StringComparison.Ordinal) != -1) ? " (Office Use Only)" : string.Empty),
                Collapsible = false,
                Width = Unit.Percentage(98),
                ID = "Asi__Wfz__MI__" + property.Name,
                ShowHeader = false
            };

            if (!string.IsNullOrEmpty(property.CssClass))
            {
                panelTemplateControl.EnableTheming = false;
                panelTemplateControl.CssClass = property.CssClass;
            }

            if (property.Description.IndexOf("__SHOW_BORDER__", StringComparison.Ordinal) != -1)
            {
                panelTemplateControl.BorderWidth = 0;
            }

            string miBOName = Utils.Mid(property.Description, "__$$", "$$__");

            if (string.IsNullOrEmpty(miBOName))
                miBOName = GetFormattedFormName(_businessItem.Table.TableName, property.Caption);

            var controllerMultiInstance = BusinessController.NewBusinessController(miBOName);
            var filter = new BusinessFilter[1];
            var webFormZSubmissionKey = new Guid(_businessItem["WebFormZSubmissionKey"].ToString());
            filter[0] = new BusinessFilter("WebFormZSubmissionKey", ComparisonType.Equal, webFormZSubmissionKey);
            controllerMultiInstance.SelectWithFilter(filter, true);
            int miMinRows, miMaxRows;
            Int32.TryParse(property.RangeStart, out miMinRows);
            Int32.TryParse(property.RangeEnd, out miMaxRows);

            if (miMinRows > 0)
            {
                var label2 = new Label
                {
                    ID = panelTemplateControl.ID + "_TextLabel2"
                };
                Label child = label2;
                panelTemplateControl.AddControl(child);
                child.Text = string.Format(("Note: You must add at least {0} {1}"), miMinRows, property.Caption);
                child.CssClass = "Info Required";
            }

            var dcolumns = new DataColumn[controllerMultiInstance.Columns.Count];
            controllerMultiInstance.Columns.CopyTo(dcolumns, 0);
            Array.Sort(dcolumns, new FormBuilderComparer());

            var grid = new RadGrid
            {
                ID = "RadGrid" + property.Name,
                AutoGenerateColumns = false,
                ShowFooter = true,
                Width = Unit.Percentage(100),
                AllowMultiRowEdit = true
            };

            grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
            
            grid.MasterTableView.ID = miBOName + "___" + property.Name;
            if (!addEnabled)
                grid.MasterTableView.ID = grid.MasterTableView.ID + "__NOADDBTN__";

            //if (miMaxRows != 0 && miMaxRows <= controllerMultiInstance.Rows.Count)
            //{
            //    grid.MasterTableView.ID = (grid.MasterTableView.ID.IndexOf("__NOADDBTN__", System.StringComparison.Ordinal) == -1) ? grid.MasterTableView.ID + "__NOADDBTN__" : grid.MasterTableView.ID;
            //}

            grid.MasterTableView.EditMode = GridEditMode.InPlace;
            grid.MasterTableView.CommandItemSettings.ShowRefreshButton = false;
            grid.MasterTableView.Caption = property.Caption;
            grid.BorderWidth = Unit.Pixel(1);
            grid.EnableViewState = true;
            grid.MasterTableView.DataKeyNames = new string[] { "FormMultiInstanceItemKey" };

            grid.ValidationSettings.EnableValidation = true;
            grid.ValidationSettings.ValidationGroup = "RadGridValidationGroup";

            //var newCol;
            foreach (var col in dcolumns)
            {
                if (!col.ColumnName.Equals("CreatedOn") && !col.ColumnName.Equals("UpdatedOn") && !col.ColumnName.Equals("BOCKey") && !col.ColumnName.Equals("UpdatedByUserKey") && !col.ColumnName.Equals("CreatedByUserKey"))
                {
                    var bProperty = col as BusinessProperty;
                    var showTotal = (bProperty.Description.IndexOf("__SHOW_TOTAL__", StringComparison.Ordinal) != -1);
                    var footerPrompt = Asi.Business.WebFormZ.Utils.Mid(bProperty.Description, "__#FP#", "#FP#__");
                    int minTotal = 0, maxTotal = 0;
                    Int32.TryParse(Asi.Business.WebFormZ.Utils.Mid(bProperty.Description, "__#MINTOTAL#", "#MINTOTAL#__"), out minTotal);
                    Int32.TryParse(Asi.Business.WebFormZ.Utils.Mid(bProperty.Description, "__#MAXTOTAL#", "#MAXTOTAL#__"), out maxTotal);
                    if (bProperty.ValueList != null || !bProperty.ValueListQuery.Equals(Guid.Empty))
                    {
                        if (bProperty.HIControlType == AtomHIControlType.DropDownList || bProperty.HIControlType == AtomHIControlType.ComboBox)
                        {
                            var newCol = new GridDropDownColumn
                            {
                                DataField = col.ColumnName,
                                HeaderText = col.Caption,
                                UniqueName = col.ColumnName,
                                FooterText = footerPrompt,
                                ReadOnly = bProperty.IsReadOnly
                            };
                            grid.MasterTableView.Columns.Add(newCol);
                        }
                        else
                        {
                            var newCol = new GridBoundColumn
                            {
                                DataField = col.ColumnName,
                                HeaderText = col.Caption,
                                UniqueName = col.ColumnName,
                                FooterText = footerPrompt,
                                ReadOnly = bProperty.IsReadOnly
                            };
                            grid.MasterTableView.Columns.Add(newCol);
                        }
                    }
                    else if (col.DataType == typeof(string))
                    {
                        var newCol = new GridBoundColumn
                        {
                            DataField = col.ColumnName,
                            HeaderText = col.Caption,
                            UniqueName = col.ColumnName,
                            FooterText = footerPrompt,
                            ReadOnly = bProperty.IsReadOnly
                        };
                        grid.MasterTableView.Columns.Add(newCol);
                    }
                    else if (col.DataType == typeof(DateTime))
                    {
                        var newCol = new GridDateTimeColumn
                        {
                            DataField = col.ColumnName,
                            HeaderText = col.Caption,
                            UniqueName = col.ColumnName,
                            FooterText = footerPrompt,
                            DataFormatString = "{0:d}",
                            ReadOnly = bProperty.IsReadOnly
                        };
                        grid.MasterTableView.Columns.Add(newCol);
                    }
                    else if (col.DataType == typeof(bool))
                    {
                        var newCol = new GridCheckBoxColumn
                        {
                            DataField = col.ColumnName,
                            HeaderText = col.Caption,
                            UniqueName = col.ColumnName,
                            FooterText = footerPrompt,
                            ReadOnly = bProperty.IsReadOnly
                        };
                        grid.MasterTableView.Columns.Add(newCol);
                    }
                    else if (col.DataType == typeof(int) || col.DataType == typeof(float) || col.DataType == typeof(decimal) || col.DataType == typeof(double))
                    {
                        var newCol = new GridNumericColumn
                        {
                            DataField = col.ColumnName,
                            HeaderText = col.Caption,
                            UniqueName = col.ColumnName,
                            FooterText = footerPrompt
                        };
                        if (showTotal) newCol.Aggregate = GridAggregateFunction.Sum;
                        grid.MasterTableView.Columns.Add(newCol);
                        if ( (minTotal > 0) || maxTotal > 0)
                        {
                            var lbl = new Label
                            {
                                Text = string.Format(("Note: {0} aggregate value shouldn't be exceed {1}"), bProperty.Caption, maxTotal)
                            };
                            lbl.Text = (minTotal > 0) ? string.Format(("Note: {0} aggregate value between {1} and {2}"), bProperty.Caption, minTotal, maxTotal) : lbl.Text;
                            lbl.CssClass = "Info Required";
                            panelTemplateControl.AddControl(lbl);
                            var validator = new CustomValidator
                            {
                                ID = bProperty.Name + "_CustomValidator",
                                ValidationGroup = "RadGridValidationGroup",
                                ErrorMessage = lbl.Text
                            };
                            panelTemplateControl.AddControl(validator);
                        }
                    }
                    else if (col.DataType == typeof(Guid))
                    {
                        var newCol = new GridDropDownColumn
                        {
                            DataField = col.ColumnName,
                            HeaderText = col.Caption,
                            UniqueName = col.ColumnName,
                            FooterText = footerPrompt
                        };
                        if (col.ColumnName.Equals("WebFormZSubmissionKey") || col.ColumnName.Equals("FormMultiInstanceItemKey"))
                            newCol.Visible = false;
                        grid.MasterTableView.Columns.Add(newCol);
                    }
                    else
                    {
                        var newCol = new GridBoundColumn
                        {
                            DataField = col.ColumnName,
                            HeaderText = col.Caption,
                            UniqueName = col.ColumnName,
                            FooterText = footerPrompt
                        };
                        grid.MasterTableView.Columns.Add(newCol);
                    }
                }
            }

            var editColumn = new GridEditCommandColumn
            {
                ButtonType = GridButtonColumnType.ImageButton,
                UniqueName = "MIEdit",
                CancelText = "Cancel",
                InsertText = "OK"
            };

            var deleteColumn = new GridButtonColumn
            {
                ConfirmText = "Are you wish to delete this item?",
                CommandName = RadGrid.DeleteCommandName,
                Text = "Delete",
                UniqueName = "DeleteColumn"
            };

            if (editEnabled)
            {
                grid.Columns.Add(editColumn);
            }
            else
            {
                grid.MasterTableView.ID += "__NOEDIT__";
                //if (addEnabled && (grid.MasterTableView.ID.IndexOf("__NOADDBTN__", StringComparison.Ordinal) == -1))
                //    grid.Columns.Add(editColumn);
            }
            if (deleteEnabled)
                grid.Columns.Add(deleteColumn);

            grid.PreRender += GridPreRender;
            grid.ItemCommand += GridItemCommand;
            grid.ItemCreated += GridItemCreated;
            grid.ItemDataBound += GridItemDataBound;
            grid.NeedDataSource += GridNeedDataSource;
            grid.MasterTableView.EnableViewState = true;
            grid.AllowAutomaticInserts = false;
            grid.AllowAutomaticUpdates = false;

            panelTemplateControl.AddControl(grid);
            divOuterControl.Controls.Add(panelTemplateControl);
            return divOuterControl;
        }
 
        void GridPreRender(object sender, EventArgs e)
        {
            DataColumn[] dcolumns = null;
            if ( (((RadGrid)sender).MasterTableView.ID.IndexOf("__NOADDBTN__", System.StringComparison.Ordinal) != -1) || GetMaxRowReached(sender, GetGridDataSource(sender, new Guid(_businessItem["WebFormZSubmissionKey"].ToString()))))
            {
                foreach (GridDataItem dataItem in ((RadGrid)sender).MasterTableView.Items)
                {
                    //((LinkButton)dataItem["EditCommandColumnUniqueName"].Controls[0]).Enabled = false; //ToDisable the Edit button
                    var cmdItem = (GridCommandItem)((RadGrid)sender).MasterTableView.GetItems(GridItemType.CommandItem)[0];
                    ((LinkButton)cmdItem.FindControl("InitInsertButton")).Visible = false;
                    ((Button)cmdItem.FindControl("AddNewRecordButton")).Visible = false;
                }
            }
            foreach (GridColumn col in ((RadGrid)sender).Columns)
            {
                if (col.DataType == typeof(int) || col.DataType == typeof(decimal) || col.DataType == typeof(float) || col.DataType == typeof(double))
                {
                    col.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
                    col.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
                    col.FooterStyle.HorizontalAlign = HorizontalAlign.Right;
                }
                dcolumns = GetGridColumnProperties(sender);
                foreach (BusinessProperty property in dcolumns)
                    if (!property.ColumnName.Equals("CreatedOn") && !property.ColumnName.Equals("UpdatedOn") && !property.ColumnName.Equals("BOCKey") && !property.ColumnName.Equals("UpdatedByUserKey") && !property.ColumnName.Equals("CreatedByUserKey"))
                        if (property.ColumnName.Equals(col.UniqueName) && property.HIControlWidth != 0)
                            col.HeaderStyle.Width = new Unit(property.HIControlWidth, UnitType.Pixel);
            }

            if (((RadGrid)sender).MasterTableView.ID.IndexOf("__NOEDIT__", StringComparison.Ordinal) == -1)
            {
                //To show the Grid always in EditMode
                foreach (GridItem item in ((RadGrid)sender).MasterTableView.Items)
                {
                    if (item is GridEditableItem)
                    {
                        GridEditableItem editableItem = item as GridDataItem;
                        if (editableItem != null) editableItem.Edit = true;
                    }
                }
                ((RadGrid)sender).Rebind();
            }
        }

        void GridItemCreated(object sender, GridItemEventArgs e)
        {
            if (( (e.Item is GridDataInsertItem) || (e.Item is GridEditableItem) ) && e.Item.IsInEditMode)
            {
                var dcolumns = GetGridColumnProperties(sender);
                var item = e.Item as GridEditableItem;
                foreach (BusinessProperty col in dcolumns)
                {
                    if (!col.ColumnName.Equals("CreatedOn") && !col.ColumnName.Equals("UpdatedOn") && !col.ColumnName.Equals("BOCKey") && !col.ColumnName.Equals("UpdatedByUserKey") && !col.ColumnName.Equals("CreatedByUserKey"))
                    {
                        if (col.DataType == typeof(int) || col.DataType == typeof(float) || col.DataType == typeof(decimal) || col.DataType == typeof(double))
                        {
                            var editor = (GridNumericColumnEditor)item.EditManager.GetColumnEditor(col.ColumnName);
                            editor.NumericTextBox.Attributes.Add("style", "text-align:right;");
                        }
                        if (col.HIControlWidth != 0)
                        {
                            if (col.DataType == typeof(int) || col.DataType == typeof(float) || col.DataType == typeof(decimal) || col.DataType == typeof(double))
                            {
                                var editor = (GridNumericColumnEditor)item.EditManager.GetColumnEditor(col.ColumnName);
                                editor.NumericTextBox.Width = new Unit(col.HIControlWidth, UnitType.Pixel);
                            }
                            else if (col.DataType == typeof(DateTime))
                            {
                                var editor = (GridDateTimeColumnEditor)item.EditManager.GetColumnEditor(col.ColumnName);
                                editor.PickerControl.Width = new Unit(col.HIControlWidth, UnitType.Pixel);
                            }
                            else if (col.DataType == typeof(bool))
                            {
                            }
                            else if (col.DataType == typeof(Guid))
                            {
                                var editor = (GridDropDownColumnEditor)item.EditManager.GetColumnEditor(col.ColumnName);
                                ((RadComboBox)editor.Controls[0]).Width = new Unit(col.HIControlWidth, UnitType.Pixel);
                            }
                            else
                            {
                                var editor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor(col.ColumnName);
                                editor.TextBoxControl.Width = new Unit(col.HIControlWidth, UnitType.Pixel);
                            }
                        }
                        if (col.Description.IndexOf("__REQ__", System.StringComparison.Ordinal) != -1)
                        {
                            if (col.ValueList != null || !col.ValueListQuery.Equals(Guid.Empty))
                            {
                                if (col.HIControlType == AtomHIControlType.DropDownList || col.HIControlType == AtomHIControlType.ComboBox)
                                {
                                    var editor = (GridDropDownColumnEditor)item.EditManager.GetColumnEditor(col.ColumnName);
                                    var cell = (TableCell)editor.ContainerControl;
                                    var validator = new AsiRequiredFieldValidator
                                    {
                                        ControlToValidate = ((RadComboBox)editor.Controls[0]).ID,
                                        ErrorMessage = "Required",
                                        ValidationGroup = "RadGridValidationGroup"
                                    };
                                    cell.Controls.Add(validator);
                                }
                                else
                                {
                                    var editor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor(col.ColumnName);
                                    var cell = (TableCell)editor.ContainerControl;
                                    editor.TextBoxControl.ID = col.ColumnName + "_ID";
                                    var validator = new AsiRequiredFieldValidator
                                    {
                                        ControlToValidate = editor.TextBoxControl.ID,
                                        ErrorMessage = "Required",
                                        ValidationGroup = "RadGridValidationGroup"
                                    };
                                    cell.Controls.Add(validator);
                                }
                            }
                            if (col.DataType == typeof(string))
                            {
                                var editor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor(col.ColumnName);
                                var cell = (TableCell)editor.ContainerControl;
                                editor.TextBoxControl.ID = col.ColumnName + "_ID";
                                var validator = new AsiRequiredFieldValidator
                                {
                                    ControlToValidate = editor.TextBoxControl.ID,
                                    ErrorMessage = "Required",
                                    ValidationGroup = "RadGridValidationGroup"
                                };
                                cell.Controls.Add(validator);
                            }
                            else if (col.DataType == typeof(DateTime))
                            {
                                var editor = (GridDateTimeColumnEditor)item.EditManager.GetColumnEditor(col.ColumnName);
                                var cell = (TableCell)editor.ContainerControl;
                                var validator = new AsiRequiredFieldValidator
                                {
                                    ControlToValidate = editor.PickerControl.ID,
                                    ErrorMessage = "Required",
                                    ValidationGroup = "RadGridValidationGroup"
                                };
                                cell.Controls.Add(validator);
                            }
                            else if (col.DataType == typeof(bool))
                            {
                                var editor = (GridBoolColumnEditor)item.EditManager.GetColumnEditor(col.ColumnName);
                                var cell = (TableCell)editor.ContainerControl;
                                var validator = new CheckBoxValidator
                                {
                                    ControlToValidate = ((CheckBox)editor.Controls[0]).ID,
                                    ErrorMessage = "Required",
                                    ValidationGroup = "RadGridValidationGroup"
                                };
                                cell.Controls.Add(validator);
                            }
                            else if (col.DataType == typeof(int) || col.DataType == typeof(float) || col.DataType == typeof(decimal) || col.DataType == typeof(double))
                            {
                                var editor = (GridNumericColumnEditor)item.EditManager.GetColumnEditor(col.ColumnName);
                                var cell = (TableCell)editor.ContainerControl;
                                editor.NumericTextBox.ID = col.ColumnName + "_ID";
                                var validator = new AsiRequiredFieldValidator
                                {
                                    ControlToValidate = editor.NumericTextBox.ID,
                                    ErrorMessage = "Required",
                                    ValidationGroup="RadGridValidationGroup"
                                };
                                cell.Controls.Add(validator);
                            }
                            else if (col.DataType == typeof(Guid))
                            {
                                var editor = (GridDropDownColumnEditor)item.EditManager.GetColumnEditor(col.ColumnName);
                                var cell = (TableCell)editor.ContainerControl;
                                var validator = new AsiRequiredFieldValidator
                                {
                                    ControlToValidate = ((RadComboBox)editor.Controls[0]).ID,
                                    ErrorMessage = "Required",
                                    ValidationGroup = "RadGridValidationGroup"
                                };
                                cell.Controls.Add(validator);
                            }
                            else
                            {
                                var editor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor(col.ColumnName);
                                var cell = (TableCell)editor.ContainerControl;
                                editor.TextBoxControl.ID = col.ColumnName + "_ID";
                                var validator = new AsiRequiredFieldValidator
                                {
                                    ControlToValidate = editor.TextBoxControl.ID,
                                    ErrorMessage = "Required",
                                    ValidationGroup = "RadGridValidationGroup"
                                };
                                cell.Controls.Add(validator);
                            }
                        }
                    }
                }
                if (e.Item.OwnerTableView.GetColumnSafe("MIEdit") != null)
                {
                    var gridId = ((RadGrid)sender).MasterTableView.ID;
                    if ((gridId.IndexOf("__NOADDBTN__", System.StringComparison.Ordinal) == -1) && (gridId.IndexOf("__NOEDIT__", StringComparison.Ordinal) != -1))
                    {
                        if (e.Item is GridDataInsertItem)
                            item["MIEdit"].Visible = true;
                        else
                            item["MIEdit"].Visible = false;
                    }
                    else
                    {
                        if (!(e.Item is GridDataInsertItem))
                        {
                            //item["MIEdit"].Controls[2].Visible = false; // Cancel Button
                            item["MIEdit"].Controls[1].Visible = true; // Space &nbsp;
                            item["MIEdit"].FindControl("CancelButton").Visible = true;
                        }
                    }
                }

                if (!(e.Item is GridDataInsertItem) && item.OwnerTableView.GetColumnSafe("DeleteColumn") != null)
                    item["DeleteColumn"].Controls[0].Visible = true;
            }
            if (!(e.Item is GridDataInsertItem))
            {
                if (e.Item.OwnerTableView.GetColumnSafe("MIEdit") != null)
                {
                    var gridId = ((RadGrid)sender).MasterTableView.ID;
                    if ((gridId.IndexOf("__NOADDBTN__", System.StringComparison.Ordinal) == -1) && (gridId.IndexOf("__NOEDIT__", StringComparison.Ordinal) != -1))
                    {
                        if ((e.Item is GridEditableItem) && (e.Item as GridEditableItem).OwnerTableView.GetColumnSafe("MIEdit") != null)
                        {
                            (e.Item as GridEditableItem)["MIEdit"].Visible = false;
                        }
                    }
                }
            }
        }

        void GridItemDataBound(object sender, GridItemEventArgs e)
        {
            DataColumn[] dcolumns = null;

            if ((((RadGrid)sender).MasterTableView.ID.IndexOf("__NOADDBTN__", System.StringComparison.Ordinal) != -1) || GetMaxRowReached(sender, GetGridDataSource(sender, new Guid(_businessItem["WebFormZSubmissionKey"].ToString()))))
            {
                if (e.Item is GridCommandItem)
                {
                    Button addButton = e.Item.FindControl("AddNewRecordButton") as Button;
                    addButton.Visible = false;
                    LinkButton lnkButton = (LinkButton)e.Item.FindControl("InitInsertButton");
                    lnkButton.Visible = false;
                }
            }

            if (e.Item is GridEditableItem && e.Item.IsInEditMode) //fire for both edit and insert        
            {
                if(dcolumns == null)
                    dcolumns = GetGridColumnProperties(sender);
                foreach (BusinessProperty col in dcolumns)
                {
                    if (!col.ColumnName.Equals("CreatedOn") && !col.ColumnName.Equals("UpdatedOn") && !col.ColumnName.Equals("BOCKey") && !col.ColumnName.Equals("UpdatedByUserKey") && !col.ColumnName.Equals("CreatedByUserKey"))
                    {
                        if (col.ValueList != null || !col.ValueListQuery.Equals(Guid.Empty))
                        {
                            if (col.HIControlType == AtomHIControlType.DropDownList || col.HIControlType == AtomHIControlType.ComboBox)
                            {
                                var editItem = e.Item as GridEditableItem;
                                GridEditManager editMgr = editItem.EditManager;
                                var ddlEditor = editMgr.GetColumnEditor(col.ColumnName) as GridDropDownListColumnEditor;
                                string selectedValue = DataBinder.Eval(editItem.DataItem, col.ColumnName).ToString();
                                DataTable dt = PopulateDropDown(col);
                                if (ddlEditor != null)
                                {
                                    ddlEditor.DataSource = dt;
                                    ddlEditor.DataValueField = string.IsNullOrEmpty(col.ValueListQueryPersistColumn) ? "Key" : col.ValueListQueryPersistColumn;
                                    ddlEditor.DataTextField = string.IsNullOrEmpty(col.ValueListQueryDisplayColumn) ? "Value" : col.ValueListQueryPersistColumn;
                                    ddlEditor.DataBind();
                                    ddlEditor.SelectedValue = selectedValue;
                                }
                            }
                        }
                    }
                }
            }
            else if (e.Item is GridFooterItem)
            {
                if (dcolumns == null)
                    dcolumns = GetGridColumnProperties(sender);
                var controller = GetGridDataSource(sender, new Guid(_businessItem["WebFormZSubmissionKey"].ToString()));
                            
                foreach (BusinessProperty col in dcolumns)
                {
                    if (!col.ColumnName.Equals("CreatedOn") && !col.ColumnName.Equals("UpdatedOn") && !col.ColumnName.Equals("BOCKey") && !col.ColumnName.Equals("UpdatedByUserKey") && !col.ColumnName.Equals("CreatedByUserKey"))
                    {
                        if (col.HIControlType == AtomHIControlType.Number && (col.Description.IndexOf("__SHOW_TOTAL__", StringComparison.Ordinal) != -1))
                        {
                            var total = controller.Compute("Sum(" + col.ColumnName + ")", string.Empty);
                            var footerText = Asi.Business.WebFormZ.Utils.Mid(col.Description, "__#FP#", "#FP#__");
                            footerText = (string.IsNullOrEmpty(footerText)) ? string.Empty : footerText + ": ";
                            footerText += ((total == DBNull.Value) ? "0" : total.ToString());
                            foreach (GridDataItem dataItem in ((RadGrid)sender).MasterTableView.Items)
                            {
                                var footerItems = ((RadGrid)sender).MasterTableView.GetItems(GridItemType.Footer)[0] as GridFooterItem;
                                if (footerItems != null)
                                    footerItems[col.ColumnName].Text = footerText;
                                if (!string.IsNullOrEmpty(col.RangeEnd))
                                    footerItems[col.ColumnName].Text = footerText + "/" + col.RangeEnd;
                            }
                        }
                    }
                }
            }
        }

        private DataTable PopulateDropDown(BusinessProperty col)
        {
            var ds = new DataSet();
            if (col.ValueList != null)
            {
                ds.Tables.Add();
                ds.Tables[0].Columns.Add(new DataColumn("Key"));
                ds.Tables[0].Columns.Add(new DataColumn("Value"));
                foreach (var pair in col.ValueList)
                {
                    DataRow dr = ds.Tables[0].NewRow();
                    dr["Key"] = pair.Second;
                    dr["Value"] = pair.First;
                    ds.Tables[0].Rows.Add(dr);
                    ds.Tables[0].AcceptChanges();
                }
            }
            else if(!col.ValueListQuery.Equals(Guid.Empty))
            {
                var myQuery = QueryBuilder.Query.NewQuery(col.ValueListQuery);

                string query = myQuery.SqlCommandText();
                using (var dbServer = new Asi.Data.DataServer())
                {
                    ds = dbServer.ExecuteDataSet(System.Data.CommandType.Text, query);
                }
            }
            return ds.Tables[0];
        }

        private static DataColumn[] GetGridColumnProperties(object sender)
        {
            var miBOName = ((RadGrid)sender).MasterTableView.ID.Split(new string[] { "__" }, StringSplitOptions.RemoveEmptyEntries)[0];
            var controllerMultiInstance = BusinessController.NewBusinessController(miBOName);
            var dcolumns = new DataColumn[controllerMultiInstance.Columns.Count];
            controllerMultiInstance.Columns.CopyTo(dcolumns, 0);
            Array.Sort(dcolumns, new FormBuilderComparer());
            return dcolumns;
        }

        private static BusinessController GetGridDataSource(object sender, Guid webFormZSubmissionKey)
        {
            var miBOName = ((RadGrid)sender).MasterTableView.ID.Split(new string[] { "__" }, StringSplitOptions.RemoveEmptyEntries)[0];
            var controllerMultiInstance = BusinessController.NewBusinessController(miBOName);
            var filter = new BusinessFilter[1];
            filter[0] = new BusinessFilter("WebFormZSubmissionKey", ComparisonType.Equal, webFormZSubmissionKey);
            controllerMultiInstance.SelectWithFilter(filter, true);
            return controllerMultiInstance;
        }

        void GridNeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            using (Asi.Security.SecurityContext.Impersonate("MANAGER"))
            {
                var miBOName = ((RadGrid)sender).MasterTableView.ID.Split(new string[] { "__" }, StringSplitOptions.RemoveEmptyEntries)[0];
                var controllerMultiInstance = BusinessController.NewBusinessController(miBOName);
                var filter = new BusinessFilter[1];
                var webFormZSubmissionKey = new Guid(_businessItem["WebFormZSubmissionKey"].ToString());
                filter[0] = new BusinessFilter("WebFormZSubmissionKey", ComparisonType.Equal, webFormZSubmissionKey);
                controllerMultiInstance.SelectWithFilter(filter, true);
                ((RadGrid)sender).DataSource = controllerMultiInstance;
            }
        }

        void GridItemCommand(object sender, GridCommandEventArgs e)
        {
            using (Asi.Security.SecurityContext.Impersonate("MANAGER"))
            {
                var miBOName = ((RadGrid)sender).MasterTableView.ID.Split(new string[] { "___" }, StringSplitOptions.RemoveEmptyEntries)[0];
                
                switch (e.CommandName)
                {
                    case RadGrid.PerformInsertCommandName:
                        InsertMIRecord(e, miBOName, sender);
                        break;
                    case RadGrid.UpdateCommandName:
                        UpdateMIRecord(e, miBOName);
                        break;
                    case RadGrid.DeleteCommandName:
                        DeleteMIRecord(e, miBOName, sender);
                        break;
                }
                GridNeedDataSource(sender, null);
                ((RadGrid)sender).EditIndexes.Clear();
                ((RadGrid)sender).Rebind();
                ((RadGrid)sender).MasterTableView.DataBind();
            }
        }

        void InsertMIRecord(GridCommandEventArgs e, string miBOName, object radGrid)
        {
            try
            {
                if (e.Item is GridEditableItem)
                {
                    var gridEditedItem = e.Item as GridEditableItem;
                    GridEditManager editMan = gridEditedItem.EditManager;
                    var weubFormZSubmissionKey = new Guid(_businessItem["WebFormZSubmissionKey"].ToString());
                    var controller = GetGridDataSource(radGrid, weubFormZSubmissionKey);
                    
                    var showTotalColumns = new Dictionary<string, string>();
                    foreach (BusinessProperty col in controller.Columns)
                    {
                        if (!col.ColumnName.Equals("CreatedOn") && !col.ColumnName.Equals("UpdatedOn") && !col.ColumnName.Equals("BOCKey") && !col.ColumnName.Equals("UpdatedByUserKey") && !col.ColumnName.Equals("CreatedByUserKey") && !col.ColumnName.Equals("FormMultiInstanceItemKey") && !col.ColumnName.Equals("WebFormZSubmissionKey"))
                        {
                            var showTotal = (col.Description.IndexOf("__SHOW_TOTAL__", StringComparison.Ordinal) != -1);
                            int minTotal = 0, maxTotal = 0;
                            Int32.TryParse(Asi.Business.WebFormZ.Utils.Mid(col.Description, "__#MINTOTAL#", "#MINTOTAL#__"), out minTotal);
                            Int32.TryParse(Asi.Business.WebFormZ.Utils.Mid(col.Description, "__#MAXTOTAL#", "#MAXTOTAL#__"), out maxTotal);
                            if ((minTotal > 0 || maxTotal > 0)) //&& showTotal)
                                showTotalColumns.Add(col.ColumnName, minTotal.ToString(CultureInfo.InvariantCulture) + "$" + maxTotal.ToString(CultureInfo.InvariantCulture));
                        }
                    }

                    foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
                    {
                        if (showTotalColumns.ContainsKey(column.UniqueName))
                        {
                            var value = showTotalColumns[column.UniqueName].ToString(CultureInfo.InvariantCulture);
                            int minTotal = Convert.ToInt32(value.Split(new char[] { '$' }, StringSplitOptions.RemoveEmptyEntries)[0]);
                            int maxTotal = Convert.ToInt32(value.Split(new char[] { '$' }, StringSplitOptions.RemoveEmptyEntries)[1]);
                            int aggregateValue = Convert.ToInt32(controller.Compute("SUM(" + column.UniqueName + ")", string.Empty));

                            DataRow[] rows = controller.Select("FormMultiInstanceItemKey = '" + gridEditedItem.OwnerTableView.DataKeyValues[gridEditedItem.ItemIndex]["FormMultiInstanceItemKey"].ToString() + "'");
                            int oldValue = 0;
                            if (rows[0][column.UniqueName] != DBNull.Value)
                                oldValue = Convert.ToInt32(rows[0][column.UniqueName]);

                            string editorText = "0";
                            var editableCol = (column as IGridEditableColumn);
                            if (editableCol != null && editableCol.IsEditable)
                            {
                                IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
                                if (editor is GridTextColumnEditor)
                                {
                                    editorText = (editor as GridTextColumnEditor).Text;
                                }
                            }
                            int newValue = 0;
                            if (string.IsNullOrEmpty(editorText))
                                newValue = Convert.ToInt32(editorText);

                            int valueToCompare = aggregateValue - oldValue + newValue;

                            if (minTotal < valueToCompare)
                            {
                                bool valid = true;
                                if (maxTotal <= 0)
                                    valid = true;
                                else if (maxTotal < valueToCompare)
                                    valid = true;
                                else
                                    valid = false;
                                var validator = FindChildControl<CustomValidator>(e.Item.Parent.Parent.Parent.Parent.Parent, column.UniqueName + "_CustomValidator");
                                validator.IsValid = valid;
                                if (!valid)
                                    return;
                            }
                        }
                    }

                    var row = controller.NewRow();
                    var newValues = new System.Collections.Hashtable();
                    e.Item.OwnerTableView.ExtractValuesFromItem(newValues, gridEditedItem);
                    row["FormMultiInstanceItemKey"] = Guid.NewGuid();
                    row["WebFormZSubmissionKey"] = weubFormZSubmissionKey;

                    ////
                    foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
                    {
                        if (column is IGridEditableColumn && !column.UniqueName.Equals("WebFormZSubmissionKey") && !column.UniqueName.Equals("FormMultiInstanceItemKey"))
                        {
                            var editableCol = (column as IGridEditableColumn);
                            if (editableCol.IsEditable)
                            {
                                IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);

                                object editorValue = null;

                                if (editor is GridTextColumnEditor)
                                {
                                    editorValue = (editor as GridTextColumnEditor).Text;
                                }

                                if (editor is GridBoolColumnEditor)
                                {
                                    editorValue = (editor as GridBoolColumnEditor).Value;
                                }

                                if (editor is GridDropDownColumnEditor)
                                {
                                    editorValue = (editor as GridDropDownColumnEditor).SelectedValue;
                                }

                                try
                                {
                                    if (column.DataType == typeof(DateTime) && editorValue != null && !string.IsNullOrEmpty(editorValue.ToString()))
                                        row[column.UniqueName] = Convert.ToDateTime(editorValue);
                                    else if (column.DataType == typeof(Guid))
                                    {
                                        if (editorValue != null && !string.IsNullOrEmpty(editorValue.ToString()))
                                            row[column.UniqueName] = new Guid(editorValue.ToString());
                                        else
                                            row[column.UniqueName] = Guid.NewGuid();
                                    }
                                    else
                                    {
                                        if (editorValue != null && !string.IsNullOrEmpty(editorValue.ToString()))
                                            row[column.UniqueName] = editorValue.ToString();
                                        else if (row.Table.Columns[column.UniqueName].AllowDBNull)
                                            row[column.UniqueName] = DBNull.Value;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    e.Canceled = true;
                                }
                            }
                        }
                    }
                    ////
                    controller.Rows.Add(row);
                    controller.Commit();
                }
            }
            catch (Exception ex)
            { }
        }

        void UpdateMIRecord(GridCommandEventArgs e, string miBOName)
        {
            try
            {
                if (e.Item is GridEditableItem)
                {
                    var gridEditedItem = e.Item as GridEditableItem;
                    GridEditManager editMan = gridEditedItem.EditManager;
                    var controller = BusinessController.NewBusinessController(miBOName);
                    var newValues = new System.Collections.Hashtable();
                    e.Item.OwnerTableView.ExtractValuesFromItem(newValues, gridEditedItem);
                    controller.SelectWithFilter(new BusinessFilter[] { new BusinessFilter("WebFormZSubmissionKey", ComparisonType.Equal, _businessItem["WebFormZSubmissionKey"]) }, true);

                    var showTotalColumns = new Dictionary<string, string>();
                    foreach (BusinessProperty col in controller.Columns)
                    {
                        if (!col.ColumnName.Equals("CreatedOn") && !col.ColumnName.Equals("UpdatedOn") && !col.ColumnName.Equals("BOCKey") && !col.ColumnName.Equals("UpdatedByUserKey") && !col.ColumnName.Equals("CreatedByUserKey") && !col.ColumnName.Equals("FormMultiInstanceItemKey") && !col.ColumnName.Equals("WebFormZSubmissionKey"))
                        {
                            var showTotal = (col.Description.IndexOf("__SHOW_TOTAL__", StringComparison.Ordinal) != -1);
                            int minTotal = 0, maxTotal = 0;
                            Int32.TryParse(Asi.Business.WebFormZ.Utils.Mid(col.Description, "__#MINTOTAL#", "#MINTOTAL#__"), out minTotal);
                            Int32.TryParse(Asi.Business.WebFormZ.Utils.Mid(col.Description, "__#MAXTOTAL#", "#MAXTOTAL#__"), out maxTotal);
                            if ((minTotal > 0 || maxTotal > 0)) //&& showTotal)
                                showTotalColumns.Add(col.ColumnName, minTotal.ToString(CultureInfo.InvariantCulture) + "$" + maxTotal.ToString(CultureInfo.InvariantCulture));
                        }
                    }

                    foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
                    {
                        if (showTotalColumns.ContainsKey(column.UniqueName))
                        {
                            var value = showTotalColumns[column.UniqueName].ToString(CultureInfo.InvariantCulture);
                            int minTotal = Convert.ToInt32(value.Split(new char[] { '$' }, StringSplitOptions.RemoveEmptyEntries)[0]);
                            int maxTotal = Convert.ToInt32(value.Split(new char[] { '$' }, StringSplitOptions.RemoveEmptyEntries)[1]);
                            int aggregateValue = Convert.ToInt32(controller.Compute("SUM(" + column.UniqueName + ")", string.Empty));

                            DataRow[] rows = controller.Select("FormMultiInstanceItemKey = '" + gridEditedItem.OwnerTableView.DataKeyValues[gridEditedItem.ItemIndex]["FormMultiInstanceItemKey"].ToString() + "'");
                            int oldValue = 0;
                            if (rows[0][column.UniqueName] != DBNull.Value)
                                oldValue = Convert.ToInt32(rows[0][column.UniqueName]);

                            string editorText = "0";
                            var editableCol = (column as IGridEditableColumn);
                            if (editableCol != null && editableCol.IsEditable)
                            {
                                IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
                                if (editor is GridTextColumnEditor)
                                {
                                    editorText = (editor as GridTextColumnEditor).Text;
                                }
                            }
                            int newValue = 0;
                            if (string.IsNullOrEmpty(editorText))
                                newValue = Convert.ToInt32(editorText);

                            int valueToCompare = aggregateValue - oldValue + newValue;

                            if (minTotal < valueToCompare)
                            {
                                bool valid = true;
                                if (maxTotal <= 0)
                                    valid = true;
                                else if (maxTotal < valueToCompare)
                                    valid = true;
                                else
                                    valid = false;
                                var validator = FindChildControl<CustomValidator>(e.Item.Parent.Parent.Parent.Parent.Parent, column.UniqueName + "_CustomValidator");
                                validator.IsValid = valid;
                                if (!valid)
                                    return;
                            }
                        }

                        if (column is IGridEditableColumn && !column.UniqueName.Equals("WebFormZSubmissionKey") && !column.UniqueName.Equals("FormMultiInstanceItemKey"))
                        {
                            var editableCol = (column as IGridEditableColumn);
                            if (editableCol.IsEditable)
                            {
                                IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);

                                object editorValue = null;

                                if (editor is GridTextColumnEditor)
                                {
                                    editorValue = (editor as GridTextColumnEditor).Text;
                                }

                                if (editor is GridBoolColumnEditor)
                                {
                                    editorValue = (editor as GridBoolColumnEditor).Value;
                                }

                                if (editor is GridDropDownColumnEditor)
                                {
                                    editorValue = (editor as GridDropDownColumnEditor).SelectedValue;
                                }

                                if (editor is GridDateTimeColumnEditor)
                                {
                                    editorValue = (editor as GridDateTimeColumnEditor).Text;
                                }

                                try
                                {
                                    DataRow[] changedRows = controller.Select("FormMultiInstanceItemKey = '" + gridEditedItem.OwnerTableView.DataKeyValues[gridEditedItem.ItemIndex]["FormMultiInstanceItemKey"].ToString() + "'");
                                    //changedRows[0][column.UniqueName] = editorValue;

                                    if (column.DataType == typeof(DateTime) && editorValue != null && !string.IsNullOrEmpty(editorValue.ToString()))
                                        changedRows[0][column.UniqueName] = Convert.ToDateTime(editorValue);
                                    else if (column.DataType == typeof(Guid))
                                    {
                                        if (editorValue != null && !string.IsNullOrEmpty(editorValue.ToString()))
                                            changedRows[0][column.UniqueName] = new Guid(editorValue.ToString());
                                        else
                                            changedRows[0][column.UniqueName] = Guid.NewGuid();
                                    }
                                    else
                                    {
                                        if (editorValue != null && !string.IsNullOrEmpty(editorValue.ToString()))
                                            changedRows[0][column.UniqueName] = editorValue.ToString();
                                        else if (changedRows[0].Table.Columns[column.UniqueName].AllowDBNull)
                                            changedRows[0][column.UniqueName] = DBNull.Value;
                                    }

                                    controller.Commit();
                                }
                                catch (Exception ex)
                                {
                                    e.Canceled = true;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            { }
        }

        void DeleteMIRecord(GridCommandEventArgs e, string miBOName, object radGrid)
        {
            try
            {
                var gridDataItem = e.Item as GridDataItem;
                if (gridDataItem != null)
                {
                    Guid formMultiInstanceItemKey = new Guid(gridDataItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["FormMultiInstanceItemKey"].ToString());
                    var controller = BusinessController.NewBusinessController(miBOName);
                    controller.SelectWithFilter(new BusinessFilter[] { new BusinessFilter("WebFormZSubmissionKey", ComparisonType.Equal, _businessItem["WebFormZSubmissionKey"]) }, true);

                    if (controller.Rows.Find(formMultiInstanceItemKey) != null)
                    {
                        controller.Rows.Find(formMultiInstanceItemKey).Delete();
                        controller.Commit();
                    }

                }
            }
            catch (Exception ex)
            { }
        }

        private bool GetMaxRowReached(object radGrid, BusinessController controller)
        {

            var businessPropertyName = ((RadGrid)radGrid).ID.Replace("RadGrid", "");
            int maxRows = Convert.ToInt32(_businessItem.BusinessProperty(businessPropertyName).RangeEnd);
            if (maxRows == 0)
                return false;
            return (maxRows <= controller.Rows.Count);
        }

        #endregion

Could any one help to solve this issue.

Thanks in advance
Prakasam
Top achievements
Rank 1
 answered on 25 Jan 2013
1 answer
102 views
Hi,

I have updated my existing application with rad controls- radcombobox, radlistbox etc, everything was working just fine but as soon as we launched our application in production the radcontrols stopped working. We disabled our state server and everything started working again but without state server our customers are facing log out /time out issues
The javascript error on the page is as below.

After looking into the details, looks like some control is affecting the state. Could someone please suggest something if they had faced similar kind of  issue.

Thanks,
Ruby

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Error parsing near' ?'
Telerik.web.UI.WebResource.axd
URI: https://....................../Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=uxSmplu....
Peter Filipov
Telerik team
 answered on 25 Jan 2013
3 answers
109 views
Hi

I cut and past from my webpages.  Multipage, panelbar controls causes the background color to be picked up with the text.  How can make it so that when I copy text the text format picked up but the background color.  If I put the same html in the space where the radpanel is then the background background color is not picked up but the text format is.  However, as soon as I put text in the radpanel or multipage then the text format and the background is picked up.  I have set the radpanel as transparent.

Is this a css solution 




















Galin
Telerik team
 answered on 25 Jan 2013
6 answers
214 views
Code Sample 

<telerik:RadComboBox ID="RadComboBox1" runat="server" Filter="Contains" EnableVirtualScrolling="false"
            EmptyMessage="Please type Here" AllowCustomText="true" EnableLoadOnDemand="false"
            MarkFirstMatch="true">
            <Items>
                <telerik:RadComboBoxItem Text="1" />
                <telerik:RadComboBoxItem Text="2" />
                <telerik:RadComboBoxItem Text="3" />
                <telerik:RadComboBoxItem Text="8" />
                <telerik:RadComboBoxItem Text="9" />
                <telerik:RadComboBoxItem Text="18" />
                <telerik:RadComboBoxItem Text="19" />
                <telerik:RadComboBoxItem Text="38" />
                <telerik:RadComboBoxItem Text="39" />
                <telerik:RadComboBoxItem Text="ABCD-39" />
                <telerik:RadComboBoxItem Text="ABCD-40" />
            </Items>
        </telerik:RadComboBox>

Problem

When I type number 9 in the above ComboBox, filter is not working.I tried with Chrome, its working fine.
I hope the problem is with IE7.

Please help me to fix it.

Thanks and Regards,
Manoj Kumar


Hristo Valyavicharski
Telerik team
 answered on 25 Jan 2013
1 answer
206 views
Hi,

I have a RadGrid on my page that contains a NestedViewTemplate containing a RadPanelBar.  I have my HierarchyLoadMode set to ServerOnDemand.  What I would like to do is when the user clicks to expand a row, I want the RadPanelBar to list a set of sub-records of row I am clicking on.  I need the RadPanelBar to contain some aspet controls, so I am using the ContentTemplate.  What I have done is, in the DetailTableDataBind function, I am querying a database for my subrecords and binding the results to the RadPanelBar for that particular GridDataItem being passed into the function.  For each row of my sub-table, I am dynamically creating my ContentTemplate from a class I created based on another post on the Telerik site.  Below is the code for this.  In additional, in my Page_Load function I am looping through the RadGrid and creating the custom template again.  Everything I have done appears to work fine with one exception.  When I first open a detail row, the RadPanelBar in that row does not have the collapse/expand ability in the header.  If I open up a second row, the first row's collapse/expand then appears and everything looks great.  But of course the second row's collapse/expand isn't visible.  So I'm always one off from this working without issue :)  I've tried using the OnInit function to do what I am doing in the Page_Load, but whenever I do anything with the RadGrid in this function, opening the nestedview causes the entire grid to disappear from the page (almost looks like it lost it's data bindings).  I have a hunch that the 'OnDetailTableDataBind' is part of my issue, I am guessing I should be doing what I am doing there somewhere else since technically I don't need to even set the e.DetailTableView.DataSource for this to work.  Does anyone have any ideas where I might be off?  My two functions are below. 

Thanks for any suggestions!
Richard
protected void OnDetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
        {
            GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
            int customerid = Convert.ToInt32(dataItem.GetDataKeyValue("customerid"));
            RadPanelBar panelBar = (RadPanelBar)dataItem.ChildItem.FindControl("pbCustomerDetails");
            using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["LocalConnectionString"].ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("", conn))
                {
                    myCommand.CommandText = "Select DateOfBirth, WorkAddress from CustomerDetail where Active=1 and CustomerID=@CustomerID ";
                    myCommand.Parameters.Add("@CustomerID", SqlDbType.Int).Value = customerid;
                    using (SqlDataAdapter adapter = new SqlDataAdapter(myCommand))
                    {
                        DataTable table = new DataTable();
                        conn.Open();
                        adapter.Fill(table);
                        conn.Close();
                         
                        panelBar.DataSource = table;
                        panelBar.DataBind();
                        for (int i = 0; i < panelBar.Items.Count; i++)
                        {
                            panelBar.Items[i].ContentTemplate = new CustomerTemplate();
                            panelBar.Items[i].ContentTemplate.InstantiateIn(panelBar.Items[i]);
                            panelBar.Items[i].DataBind();
                            panelBar.Items[i].Expanded = true;
                        }
                         
                        panelBar.DataBind();
                        e.DetailTableView.DataSource = table;
                    }
                             
                }
            }
        }

protected void Page_Load(object sender, EventArgs e)
        {
            foreach (GridDataItem item in CustomerGrid.Items)
            {
                if (item.Expanded)
                {
                    RadPanelBar panelBar = (RadPanelBar)item.ChildItem.FindControl("pbCustomerDetails");
                    for (int i = 0; i < panelBar.Items.Count; i++)
                    {
                        panelBar.Items[i].ContentTemplate = new CustomerTemplate();
                        panelBar.Items[i].ContentTemplate.InstantiateIn(panelBar.Items[i]);
                        panelBar.Items[i].DataBind();
                    }
                    panelBar.DataBind();
                }
 
            }           
        }
Boyan Dimitrov
Telerik team
 answered on 25 Jan 2013
3 answers
124 views
I've added another button to the standard edit template, 'Update then edit next row'.  I need to create an event that will put the next row, if it exists, into edit mode.

protected void rgDemandForecast_OnItemCreated(object source, GridItemEventArgs e)
        {
            if (e.Item is Telerik.Web.UI.GridEditFormItem && e.Item.IsInEditMode)
            {
                LinkButton linkButton = new LinkButton();
                linkButton.Text = "Update And Edit Next Row";
                linkButton.CommandName = "Update";
  
                linkButton.Attributes["onclick"] = "some javascript";
                      //or
                linkButton.Click += updateAndEditNextRow_OnClick;
  
                
LinkButton update = e.Item.FindControl("UpdateButton") as LinkButton;
                update.Parent.Controls.Add(new LiteralControl(" "));
                update.Parent.Controls.Add(linkButton);
            }
  
  
        }

Can someone give me a general outline of which javascript methods i need to get the current row and then put the next row into edit mode?

I don't mind doing this in my updateAndEditNextRow_OnClick method, but would prefer to keep this client-side.
Danny
Top achievements
Rank 2
 answered on 25 Jan 2013
3 answers
102 views
Hi!

I am trying to overcome a limitation in RadGrid (which I think is still around, I am using version 2010.1.309.35):
If AllowMultiRowSelection = true, and the user selects multiple rows by holding down the Shift-key, there is no postback even if

EnablePostBackOnRowClick = true.


There is a workaround described here:
http://stackoverflow.com/questions/7424397/telerik-radgrid-onrowselected-events-all-done-event-for-multiple-selection/14381154#14381154

I have slightly modified the client code to look like this:
function IW_RowSelected(sender, eventArgs) {
    var e = eventArgs.get_domEvent();
    if (!sender.AllowMultiRowSelection || !e.shiftKey) {
        // Multiple row not enabled or shift not pressed, nothing to do
        return;
    }
      
    if (window.rowSelectedTimeout) {
        // If selecting multiple rows, clear the previous row's rowSelectedTimeout
        window.clearTimeout(window.rowSelectedTimeout);
    }
  
    rowSelectedTimeout = window.setTimeout(function() {
        window.rowSelectedTimeout = null;
        alert('rows selected'); // Should force a postback here
    }, 10);
}

And it works fine. There is just one piece missing: How do I force a postback when the "last" row has been selected? Right now, all I do is an "alert('rows selected')", but I need to force a postback so that my server-side code can detect which rows are currently selected.

If it matters, I use an ASP.NET UpdatePanel to get partial updates.

Thanks!
/Fredrik
Kostadin
Telerik team
 answered on 25 Jan 2013
1 answer
128 views
Hello!
In my project I use RadGrid with dynamic columns creation and configuration. Available columns is stored in database and columns set is depend on user group. User can resize, hide/show and reorder columns and configuration is persisted in db using REST ajax requests to service. Filtering and grouping also is enabled. Dynamically created at PageInit event Grid is wrapped by ASP.NET Update panel and binded at server side using NeedDataSource event. Grid.MasterTableView.EnableColumnsViewState = false (otherwise grid throws exception at postback request). All is OK untill user will not start columns reoredering. If user reorder columns, new order will be stored at db, but Ids of the links in column headers that responsible for invoking sort operation still the same... so at the next postback request (for example - rebind) we will get sorting not on the target column, but on the column that be place at that position before reordering. In you sample demo with client-side columns reordering sorting is disabled... Because of grid doesn't support sorting with enabled client-side reordering?
Angel Petrov
Telerik team
 answered on 25 Jan 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Dean
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Emil
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Dean
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Emil
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?