This is a migrated thread and some comments may be shown as answers.

Hide Edit Image Button, Keep Insert/Cancel

8 Answers 398 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bailey Everitt
Top achievements
Rank 1
Bailey Everitt asked on 06 Mar 2009, 03:44 AM
Hey Everyone,

I'm having trouble making the Edit Image button on each record invisible.  I want to be able to Add and Delete Records, but not be able to Edit them.  However, if I do not generate/create an Edit button, the Insert/Cancel image buttons do not appear when I add a new record.  Can someone please tell me the correct settings I need?  Thanks.

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Mar 2009, 06:43 AM
Hello Mathew,

I am not sure about the issue that you are facing. I guess you want image buttons for insert and delete records and don't want to edit the records. If that the case, you can remove the GridEditCommandColumn from the column collection and set the EditFormSettings as shown below. Hope this helps.

ASPX:
<EditFormSettings EditColumn-ButtonType="ImageButton"></EditFormSettings> 

Thanks,
Princy.
0
Bailey Everitt
Top achievements
Rank 1
answered on 06 Mar 2009, 05:37 PM
The problem is that if I do not include a GridEditCommandColumn (or auto generate an Edit column) the Insert/Cancel image buttons do NOT appear when I choose to Add a New Record.  My code is below.  Thanks for the help.


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CodesFailureGroups.aspx.cs" Inherits="Web.CodesFailureGroups" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>Untitled Page</title> 
    <telerik:RadCodeBlock ID="uxRadCodeBlock" runat="server">  
        <style type="text/css">  
            html, body, form  
            {  
                height: 100%;  
                width: 100%;  
                padding: 0px;  
                margin: 0px;  
                overflow: hidden;  
            }  
        </style> 
 
        <script type="text/javascript">  
   function centerUpdatePanel()  
   {  
        centerElementOnScreen(document.getElementById("uxRadAjaxLoadingPanel"));  
   }  
   function centerElementOnScreen(element)  
   {  
        var scrollTop = document.body.scrollTop;  
        var scrollLeft = document.body.scrollLeft;  
        var viewPortHeight = document.body.clientHeight;  
        var viewPortWidth = document.body.clientWidth;  
        if (document.compatMode == "CSS1Compat")  
        {  
         viewPortHeight = document.documentElement.clientHeight;  
         viewPortWidth = document.documentElement.clientWidth;  
         scrollTop = document.documentElement.scrollTop;  
         scrollLeft = document.documentElement.scrollLeft;  
        }  
        var topOffset = Math.ceil(viewPortHeight/2 - element.offsetHeight/2);  
        var leftOffset = Math.ceil(viewPortWidth/2 - element.offsetWidth/2);  
        var top = scrollTop + topOffset - 40;  
        var left = scrollLeft + leftOffset - 70;  
           element.style.position = "absolute";  
        element.style.top = top + "px";  
        element.style.left = left + "px";  
    }  
        </script> 
 
    </telerik:RadCodeBlock> 
</head> 
<body> 
    <form id="form1" runat="server">  
    <telerik:RadScriptManager ID="uxRadScriptManagerCodes" runat="server">  
    </telerik:RadScriptManager> 
    <telerik:RadAjaxLoadingPanel IsSticky="true" ID="uxRadAjaxLoadingPanel" runat="server" 
        Height="75px" Width="75px">  
        <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading1.gif") %>' 
            style="border: 0px;" /> 
    </telerik:RadAjaxLoadingPanel> 
    <telerik:RadGrid ID="uxCodesGrid" runat="server" AllowSorting="True"   
        GridLines="None" OnNeedDataSource="uxCodesGrid_NeedDataSource" 
        Skin="WebBlue" 
        OnItemCreated="uxCodesGrid_ItemCreated"   
        AutoGenerateColumns="False"   
        ondetailtabledatabind="uxCodesGrid_DetailTableDataBind"   
        onitemdatabound="uxCodesGrid_ItemDataBound">  
        <HeaderContextMenu EnableTheming="True">  
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </HeaderContextMenu> 
        <MasterTableView CommandItemDisplay="Top"   
            DataKeyNames="FailureGroupsPrimaryKey" EditMode="InPlace" 
            TableLayout="Fixed">  
            <DetailTables> 
                <telerik:GridTableView runat="server" CommandItemDisplay="Top"   
                    DataKeyNames="FailuresPrimaryKey" EditMode="InPlace" Name="Failures">  
                    <ParentTableRelation> 
                        <telerik:GridRelationFields DetailKeyField="FailuresPrimaryKey"   
                            MasterKeyField="FailureGroupsPrimaryKey" /> 
                    </ParentTableRelation> 
                    <CommandItemSettings AddNewRecordImageUrl="UIComponents\Images\add.gif"   
                        RefreshText="" /> 
                    <RowIndicatorColumn> 
                        <HeaderStyle Width="20px" /> 
                    </RowIndicatorColumn> 
                    <ExpandCollapseColumn> 
                        <HeaderStyle Width="20px" /> 
                    </ExpandCollapseColumn> 
                    <Columns> 
                        <telerik:GridBoundColumn DataField="FailuresPrimaryKey"   
                            HeaderText="FailuresPrimaryKey" ReadOnly="True"   
                            SortExpression="FailuresPrimaryKey" UniqueName="FailuresPrimaryKey">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridDropDownColumn DataField="FailuresPrimaryKey" HeaderText="Failure"   
                            ListTextField="Failure" ListValueField="FailuresPrimaryKey"   
                            UniqueName="Failure">  
                        </telerik:GridDropDownColumn> 
                        <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"   
                            FilterListOptions="VaryByDataTypeAllowCustom" Text="Delete" UniqueName="Delete">  
                        </telerik:GridButtonColumn> 
                    </Columns> 
                    <EditFormSettings> 
                        <EditColumn ButtonType="ImageButton">  
                        </EditColumn> 
                    </EditFormSettings> 
                </telerik:GridTableView> 
            </DetailTables> 
            <CommandItemSettings AddNewRecordImageUrl="UIComponents\Images\add.gif" AddNewRecordText="Add New Record" 
                RefreshText="" /> 
            <RowIndicatorColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn Visible="True">  
                <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
            <Columns> 
                <telerik:GridBoundColumn DataField="FailureGroupsPrimaryKey"   
                    HeaderText="FailureGroupsPrimaryKey" ReadOnly="True"   
                    SortExpression="FailureGroupsPrimaryKey"   
                    UniqueName="FailureGroupsPrimaryKey">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Description" HeaderText="Description"   
                    SortExpression="Description" UniqueName="Description">  
                </telerik:GridBoundColumn> 
            </Columns> 
            <SortExpressions> 
                <telerik:GridSortExpression FieldName="Description" /> 
            </SortExpressions> 
            <EditFormSettings> 
                <EditColumn ButtonType="ImageButton">  
                </EditColumn> 
            </EditFormSettings> 
        </MasterTableView> 
        <FilterMenu EnableTheming="True">  
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </FilterMenu> 
    </telerik:RadGrid> 
    <telerik:RadAjaxManager runat="server" ID="uxRadAjaxManager">  
        <ClientEvents OnRequestStart="centerUpdatePanel();"></ClientEvents> 
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="uxCodesGrid">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="uxCodesGrid" LoadingPanelID="uxRadAjaxLoadingPanel" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    </form> 
</body> 
<head> 
    <meta http-equiv="PRAGMA" content="NO-CACHE">  
</head> 
</html> 
 
0
Daniel
Telerik team
answered on 09 Mar 2009, 10:23 AM
Hello Matthew,

Test the following suggestion:

<telerik:GridEditCommandColumn UniqueName="myEditColumn" /> 

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    if (e.Item is GridHeaderItem) 
        RadGrid1.MasterTableView.GetColumn("myEditColumn").Display = RadGrid1.MasterTableView.IsItemInserted; 
    if (e.Item is GridEditableItem && !e.Item.IsInEditMode) 
        (e.Item as GridEditableItem)["myEditColumn"].Controls[0].Visible = false

Let us know whether this helps.

Kind regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sean
Top achievements
Rank 1
answered on 13 May 2009, 06:46 PM
hello Daniel,

I am having a formatting issue with my radgrid whenever I switch to insert mode using your code snippet.
The grid seems to swift to the right when the "insert" and "cancel" button appear in insert mode.
Below those 2 buttons, the edit is blank (no gridline or background color)
Any fix?
0
Daniel
Telerik team
answered on 19 May 2009, 07:37 AM
Hello Sroun,

You can try to simply set the column visibility to false:
<telerik:GridEditCommandColumn UniqueName="myEditColumn" Visible="false" /> 

Hope this helps.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Peter Obiefuna
Top achievements
Rank 1
answered on 03 Jun 2009, 10:07 PM
I have this same problem and would want my Visible="false" generated dynamically from the state of another control on the page

The following in the general idea. But somehow, this does not work.

Visible = '<%=chkCanEdit.Visible%>'
0
Shinu
Top achievements
Rank 2
answered on 04 Jun 2009, 06:29 AM
Hi Peter,

Try to set the visibilty of the Edit column in the code behind as shown below.

CS:
 
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        RadGrid1.MasterTableView.GetColumn("editCol").Visible = chkCanEdit.Visible; 
        RadGrid1.MasterTableView.Rebind(); 
    } 


Shinu
0
Peter Obiefuna
Top achievements
Rank 1
answered on 04 Jun 2009, 03:12 PM
Nice! Thanks.
Tags
Grid
Asked by
Bailey Everitt
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Bailey Everitt
Top achievements
Rank 1
Daniel
Telerik team
Sean
Top achievements
Rank 1
Peter Obiefuna
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or