Telerik RadGrid GridEditCommandColumn Only Shows Text Rather Than Default Image



TODO:

You have a RadGrid and the edit column does not show the edit button, only the "edit" text

 

SOLUTION:

In my case the following was in my web.config,

<add key="Telerik.EnableEmbeddedSkins" value="false"/>
   

so the solution was as follows.

  1. Add EnableEmbeddedSkins="true" to your RadGrid declaration
  2. Add Skin="" to your RadGrid declaration


NOTES:

How To Disable Edit Of A Particular RadGrid Cell And Hide The Edit Control



TODO:

Have you ever wanted to remove a TextBox or other Control from a particular cell in a RadGrid?  This is particularly useful when you want to conditionally allow edits based on certain data in the record.

 

SOLUTION:

protected void rgMyGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
        //do it when in edit mode
     if (e.Item.IsInEditMode && e.Item is GridEditableItem)
     {
          GridEditableItem dataItem = e.Item as GridEditableItem;

          //if we have a particular type, do not allow the cell to be edited.  if it is not this type, we can allow the cell to be edited
          if (((Employee)dataItem.DataItem).SSN == Ssn1 ||
                ((Employee)dataItem.DataItem).SSN == Ssn2)
          {
                //we have one that needs to have name edit disabled and hidden
                dataItem["Name"].Enabled = false;
                dataItem["Name"].Controls[0].Visible = false;

                //now create a label and add it to the controls of the "Name" cell.  Set the text of the label to the text that is in the edit TextBox that we hid.
                Label descLabel = new Label();
                descLabel.Text = (dataItem["Name"].Controls[0] as TextBox).Text;
                dataItem["Name"].Controls.Add(descLabel);
          }
     }
}

 

NOTES:

There are no notes on this topic

How To Remove An Image From The Header Text Of A RadGrid Column



TODO:

Have you ever wanted to remove an image from the Header Text of a Telerik RadGrid?

 

SOLUTION:

/// <summary>
/// Add Header Image
/// </summary>
/// <param name="TargetGrid"></param>
/// <param name="HeaderText"></param>
protected void RemoveGridHeaderImage(RadGrid TargetGrid, string HeaderText)
{
     GridHeaderItem headerItem = (GridHeaderItem)TargetGrid.MasterTableView.GetItems(GridItemType.Header)[0];
     try
     {
          headerItem[HeaderText].Controls.AddAt(1, space);
          headerItem[HeaderText].Controls.AddAt(2, img);
     }
     catch
     {
     }
}

 

NOTES:

All you have to do, is call this method in the PreRender() method of your RadGrid.  You can use this in conjunction with adding an image to a RadGrid Header at this link, which will allow you to toggle the image on and off depending on the contents of the grid.

How To Add An Image To The Header Text Of a RadGrid Column



TODO:

Have you ever wanted to add an image to the Header Text of a Telerik RadGrid?

 

SOLUTION:

/// <summary>
/// Add Header Image
/// </summary>
/// <param name="TargetGrid"></param>
/// <param name="HeaderText"></param>
/// <param name="ImageUrl"></param>
protected void AddGridHeaderImage(RadGrid TargetGrid, string HeaderText, string ImageUrl)
{
     GridHeaderItem headerItem = (GridHeaderItem)TargetGrid.MasterTableView.GetItems(GridItemType.Header)[0];
     Image img = new Image();
     Literal space = new Literal();
     space.Text = " ";
     try
     {
          img.ImageUrl = ImageUrl;
          headerItem[HeaderText].Controls.AddAt(1, space);
          headerItem[HeaderText].Controls.AddAt(2, img);
     }
     catch
     {
     }
     finally
     {
          img.Dispose();
     }
}

 

NOTES:

All you have to do, is call this method in the PreRender() method of your RadGrid.

How To Add A Custom Filter To A RadEditor That Is An EditItem Of A RadGrid



TODO:

Have you ever wanted to add a custom filter to a RadEditor that is a EditItemTemplate in a RadGrid that lives in a RadAjaxPanel?  To get this accomplished, some out of the ordinary things need to happen, or else you will end up with the dreaded 'Telerik.Web.UI.Editor' is undefined error on page load.

 

SOLUTION:

1. Add JavaScript to the page, that will do some things we want to happen when we go from design to html mode in the RadEditor.

<telerik:RadCodeBlock ID="rcbGirdLoaded" runat="server">
        <script type="text/javascript">
            function StripXSS(content) {
                var newContent = content;
                //Make changes to the content and return it      
                newContent = newContent.replace(/iframe/gi, "");
                newContent = newContent.replace(/javascript:alert/gi, "");
                newContent = newContent.replace(/javascript/gi, "");
                
                //do some other stuff
                return newContent;
            }

            function CreateRadEditorXSSFilter(editor, args) {
                editor.get_filtersManager().add(new MyFilter());
            }

            MyFilter = function () {
                MyFilter.initializeBase(this);
                this.set_isDom(false);
                this.set_enabled(true);
                this.set_name("RadEditor XSS filter");
                this.set_description("RadEditor XSS filter");
            }
            MyFilter.prototype =
            {
                getHtmlContent: function (content) {
                    return StripXSS(content);
                },
                getDesignContent: function (content) {
                    return StripXSS(content);
                }
            }

            //on grid created
            function AddXSSFilter()
            {
                MyFilter.registerClass('MyFilter', Telerik.Web.UI.Editor.Filter);
            }
        </script>
    </telerik:RadCodeBlock>

 

2.  Create your RadEditor, and set OnClientLoad to our function that creates the filter.

<telerik:RadEditor runat="server" ID="txtDescription" OnClientLoad="CreateRadEditorXSSFilter" RegisterWithScriptManager="false"  ToolsWidth="250px" AllowScripts="false" EditModes="Design,Html" >
</telerik:RadEditor>

 

3. Add the client setting to the RadGrid, that will fire when a PopUp is showing (Here we add the filter)

<ClientSettings>
     <ClientEvents OnPopUpShowing="AddXSSFilter" />
</ClientSettings>

 

NOTES:

Basically, MyFilter.registerClass('MyFilter', Telerik.Web.UI.Editor.Filter); , will cause an error on page load, because 'Telerik.Web.UI.Editor' will be undefined.  We only want to execute that line, once the grid is loaded, and more so when the RadEditor is known.  Since this is in AJAX, and a PopUp editor window, that line needs to happen when the client 'PopUpShowing' event is called.  These code snippets show how to accomlish this.

How To Use A Telerik RadGrad In PopUp Mode For Inserts, And InPlace For Edits



TODO:

Have you ever wanted to use a popup window for inserts to a Telerik RadGrid, but then allow editing to be done InPlace?

 

SOLUTION:

protected void rgdDocuments_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
     if (e.CommandName == RadGrid.EditCommandName)
     {
          rgdDocuments.MasterTableView.EditMode = GridEditMode.InPlace;
     }
     if (e.CommandName == RadGrid.InitInsertCommandName)
     {
          rgdDocuments.MasterTableView.EditMode = GridEditMode.PopUp;
     }
}


NOTES:

There are no notes on this topic.

Possible Cause For "Sys.ArgumentException: Value must not be null for Controls and Behaviors. Parameter name: element" When Using Telerik RadGrid



TODO:

You have a Telerik RadGrid and when you click on the Add button, you get the " Sys.ArgumentException: Value must not be null for Controls and Behaviors. Parameter name: element" error.

 

SOLUTION:

In my case I had the following structure:

Panel 1

FormGroup (a control we built)

Panel 2

RadGrid 1

 

I had AjaxSettings in my code behind for "Panel 1" and "FormGroup".  Having AjaxSettings for the nested controls caused my issue.  I removed the AjaxSetting for "FormGroup" and the issue went away


NOTES:

There are no notes on this topic.

How To Dynamically Sort a List<T> During the SortCommand Of a Telerik RadGrid



TODO:

Have you ever wanted to catch the Sort Event of a Telerik RadGrid, and sort your datasource?   This comes in handy if you are using the rows in the grid as a 1 to 1 map with items in the datasource.  This saves you from needing to worry about working with the rows and columns of a grid, but instead you can work with the List of Objects, and simply ReBin().

 

SOLUTION:

protected voidrgdMyGrid_SortCommand(object source, Telerik.Web.UI.GridSortCommandEventArgs e)
{  
    //check the sort order.  if it is descending, then we need to order list that way, otherwise use default of ascending.
    Func<MyObject, string> orderByColumn =null;
    
    //Figure out which sort column
    switch (e.SortExpression)
    {
        case "FirstName":
            orderByColumn = s => s.FirstName;
            break;
        case "LastName":
            orderByColumn = s => s.LastName;
            break;
        case "Telephone":
            orderByColumn = s => s.Telephone;
            break;
    }
    
    //now check the sort order, and sort accordingly
    if (e.NewSortOrder == GridSortOrder.Descending)
    {
        myDataSource = myDataSource.OrderByDescending(orderByColumn).ToList();
    }
    else
    {
        myDataSource = myDataSource.OrderBy(orderByColumn).ToList();
    }
    rgdMyGrid.DataSource = null;
    rgdMyGrid.Rebind();
}

 

NOTES:

MyDataSource is a List<MyObject>.  I was using the datasource for the grid and had to keep them in sync, because sorting the grid did not by default sort the datasource.  You also need to sort the datasource on insert, update, and delete of an item in the RadGrid, if a sort column is selected.