2

I am trying to remove the links that are displayed in a Telerik RadGrid by default. Here is what the grid looks like before I try to remove the edit link:

before I try to remove the edit link

I have found this snippet of code, it is used to remove the edit link:

if (!IsPostBack)
            {
                foreach (GridItem item in RGV_POI.MasterTableView.Items)
                {
                    if (item is GridEditableItem)
                    {
                        GridEditableItem editableItem = item as GridDataItem;
                        editableItem.Edit = true;


                    }
                }
                RGV_POI.Rebind();
            }

This is how the grid looks after the code:

how to grid looks after I try the code

The edit link still shows up on the first item. Is there a way to remove the edit, update, and cancel link on each item in the RadGrid? I want to be able to remove/disable the links, using a button click event. Then be able to add/enable the links back, using a button click event.

nate
  • 1,418
  • 5
  • 34
  • 73
  • It seems like your current code simply makes the lines editable, not to remove the edit link. Which is why update/cancel shows up. Is that the intention? – LogicaLInsanity Sep 29 '14 at 14:06
  • @LogicaLInsanity No I wanted to make them uneditable, but I see what you are saying now. Even if I set it to false, the edit button still shows up – nate Sep 29 '14 at 14:07

3 Answers3

0

I'm not aware of Telerik RadGrid Control, but for sure the control should inherit asp:GridView. You can make links not visible in RowDataBound event. Here how you can do it.

Add OnItemDataBound="Grid_ItemDataBound" on the grid view.

In the code behind:

    protected void Grid_ItemDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Item.DataItem == null)
            return;

        //cell of all the link button edit/update etc.
        TableCell cell = e.Item.Cells[//index of the column];

        foreach(Control c in cell.Controls)
        {
            c.Visible = false;
        }  
    }

You should check the ID of the cancel, edit, update buttons somehow. Probably you should give more information about the controls in the aspx.

EDIT:

Use OnItemDataBound event it existing in their documentation: http://www.telerik.com/help/aspnet-ajax/events_t_telerik_web_ui_radgrid.html

mybirthname
  • 17,949
  • 3
  • 31
  • 55
0

The edit link button in a RadGrid is actually a column itself, specifically a GridEditCommandColumn. In order to show/hide this in the event of a button click, you would have to essentially rebuild all the columns programatically in the click event handler, including or excluding the GridEditCommandColumn as needed. You cannot add or remove a single column programatically when the rest of the grid is created declaratively. It would be useful if we could see more of how the grid is declared and built in your application.

Creating a RadGrid Programatically

It may be possible to change the GridEditCommandColumn.Display property, however. If you can get a handle on the column itself, instead of the individual cells, you may be able to adjust this as needed in your button click events.

Bryan Ulfers
  • 125
  • 15
  • Okay how would I do it. – nate Oct 07 '14 at 15:32
  • The first example [here](http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html) shows how to define columns programatically and bind data to them. They are doing it in the page_Load event. You would have to do it in the button click events instead. – Bryan Ulfers Oct 07 '14 at 20:35
0

You should remove the GridEditCommandColumn if you do not want your items editable. Another option is to change its visibility on the server through its Visible/Display property. You can use the grid's GetColumnSafe(columnName) method to get the neded reference: http://www.telerik.com/help/aspnet-ajax/grid-using-getitems-getcolumn-methods.html

To get rid of the update/cancel buttons, you can use a custom template, although I do not see why you would need to do that if your grid is not editable: http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/form-template-update/defaultcs.aspx

rdmptn
  • 5,413
  • 1
  • 16
  • 29
  • I want to remove the edit link when the web form loads, then enable it if the user needs to change data. – nate Oct 07 '14 at 15:31
  • How do you know the user needs to change data? On the server or on the client? We have shown how to remove/add these link buttons on the server. Here is how to hide a column with JavaScript: http://demos.telerik.com/aspnet-ajax/grid/examples/client/clientsideapi/defaultcs.aspx – rdmptn Oct 08 '14 at 12:19