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

<telerik:GridEditCommandColumn>

4 Answers 416 Views
Grid
This is a migrated thread and some comments may be shown as answers.
d-cpt
Top achievements
Rank 2
d-cpt asked on 04 Sep 2008, 08:40 PM
I use this GridEditCommandColumn for automatic (from demo) add/delete row. How to disable the Edit function? Thank you.

d-cpt

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Sep 2008, 04:33 AM
Hi,

Try the following code snippet to prevent editing in Grid.

CS:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            item.Edit = false
        } 
   } 

If you want to remove the auto generated edit column set AutoGenerateEditColumn to false.

Thanks
Shinu.
0
d-cpt
Top achievements
Rank 2
answered on 05 Sep 2008, 02:04 PM
Hi Shinu,
I tried your code snippet but I still can click on the Edit icon of a row to get row edit. When I click away, the page gave this error:
Failed to load viewstate.  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
Thank you,
d-cpt

Here is the grid:

<telerik:RadGrid ID="radgridAdmin" runat="server" AllowPaging="True"

Skin="WebBlue" ShowStatusBar="True" AllowSorting="True"

AutoGenerateColumns="False" GridLines="None"

ShowFooter="True" DataSourceID="SqlDataSource1" AllowAutomaticInserts=True AllowAutomaticDeletes=True

OnPreRender="radgridAdmin_PreRender"

OnItemInserted="radgridAdmin_ItemInserted"

OnDataBound="radgridAdmin_DataBound"

OnItemCreated="radgridAdmin_ItemCreated">

<PagerStyle Mode="NextPrevNumericAndAdvanced" />

<MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="PersonId" EditMode=InPlace CommandItemDisplay="TopAndBottom" HorizontalAlign="NotSet" AutoGenerateColumns="False">

<RowIndicatorColumn>

<HeaderStyle Width="20px"></HeaderStyle>

</RowIndicatorColumn>

<ExpandCollapseColumn>

<HeaderStyle Width="20px"></HeaderStyle>

</ExpandCollapseColumn>

<Columns>

<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" >

<ItemStyle CssClass="MyImageButton" />

</telerik:GridEditCommandColumn>

<telerik:GridDropDownColumn DataField="PersonID" DataSourceID="SqlDataSource2"

HeaderText="Administrator Name" ListTextField="UserName" ListValueField="PersonID"

UniqueName="PersonID" HeaderStyle-Width=50%>

<HeaderStyle Width="50%"></HeaderStyle>

</telerik:GridDropDownColumn>

<telerik:GridButtonColumn ConfirmText="Delete this admin?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton"

CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">

<ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />

</telerik:GridButtonColumn>

</Columns>

<EditFormSettings>

<EditColumn UniqueName="EditCommandColumn1"></EditColumn>

</EditFormSettings>

</MasterTableView>

<FilterMenu EnableTheming="True">

<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

</FilterMenu>

</telerik:RadGrid>

0
Accepted
Princy
Top achievements
Rank 2
answered on 08 Sep 2008, 05:56 AM
Hello,

You can check out the following code snippet to disable the Edit buttons in the EditCommandColumn.
aspx:
<telerik:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="images/Edit.gif" UniqueName="EditCommandColumn"
</telerik:GridEditCommandColumn> 

cs:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            ImageButton imageButton = (ImageButton)item["EditCommandColumn"].Controls[0]; 
            imageButton.Enabled = false
        } 
    } 

Princy.
0
d-cpt
Top achievements
Rank 2
answered on 08 Sep 2008, 03:23 PM
Thanks, Princy. It works.

I actually went a bit further to reset default CssClass to a new one in which sets cursor:default insteads of cursor:hand When user has the mouse over the column or the image, the cursor doesn't change. this would improve the user experience a bit better.

if

(imageButton.ImageUrl == "myEditImagePath")
{
item[
"EditCommandColumn"].CssClass = "MyImageButtonDisabled";
imageButton.Enabled =
false;
imageButton.CssClass =
"MyImageButtonDisabled";
imageButton.ToolTip =
"";
}

Regards,
 
d-cpt

Tags
Grid
Asked by
d-cpt
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
d-cpt
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Share this question
or