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

[Solved] Restricting user to one edit at a time.

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul Buxton
Top achievements
Rank 1
Paul Buxton asked on 16 Apr 2009, 09:15 AM
Hi,

I'm looking at the Automatic editing aspects of the Grid.

I'm having some slight issues with functionality.

The column that is also DataKeyName I require to be editable when the user is is Add New mode, but ReadOnly in Update mode.

It appears that when in Insert or Update mode the column isn't editable at all.  If we were using identity columns for the PK, then this wouldn't be an issue, but in our case we aren't.

I used the following handler in the code behind, to try to enable this, but when doing the Insert it cannot resolve the field @Code in the SqlDataSource.  Also, I notice that if I have an Update popup open and an Add New popup open, that the ItemCommand handler affects both popups?


protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            
            GridBoundColumn id = (GridBoundColumn)e.Item.OwnerTableView.GetColumnSafe("Code") as GridBoundColumn;
            id.Display = true;
            if (e.CommandName == RadGrid.InitInsertCommandName)
            {
              
                id.ReadOnly = false;
            }
            else
            {
                id.ReadOnly = true;
            }





Is it possible to have the DataKeyName editable in Add New, but ReadOnly in Update?  

I'm sure its a simple thing I missed, but I can't see it.

Can you help?


Regards
Paul



-----

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EditDateCodes.ascx.cs" Inherits="SpacetrakWebMaintenance.UserControls.EditDateCodes" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>


<asp:ScriptManager ID="ScriptManager1" runat="server" />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
            EnablePageHeadUpdate="False">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:spacetrakConnectionString %>"
            SelectCommand="SELECT CODE, [DESC], WORDS FROM YEARCODE" DeleteCommand="DELETE FROM YEARCODE WHERE CODE = @CODE" InsertCommand="INSERT INTO YEARCODE (CODE, [DESC], WORDS) VALUES (@CODE, @DESC, @WORDS)" UpdateCommand="UPDATE YEARCODE SET [DESC] = @DESC, WORDS=@WORDS WHERE CODE =@CODE">
        </asp:SqlDataSource>
    
    </div>
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
            AllowAutomaticUpdates="True" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
            GridLines="None" Height="400px" Skin="Inox" SkinID="Inox" OnItemCommand="RadGrid1_ItemCommand" OnItemDataBound="RadGrid1_ItemDataBound">
            <MasterTableView CommandItemDisplay="Bottom" DataKeyNames="CODE" DataSourceID="SqlDataSource1"
                EditMode="PopUp" Height="400px">
                <RowIndicatorColumn>
                    <HeaderStyle Width="20px" />
                </RowIndicatorColumn>
                <ExpandCollapseColumn>
                    <HeaderStyle Width="20px" />
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridEditCommandColumn>
                    </telerik:GridEditCommandColumn>
                    <telerik:GridButtonColumn UniqueName="ButtonColumn" Text="Delete" CommandName="Delete" />
                    <telerik:GridBoundColumn DataField="CODE" DataType="System.Int32" HeaderText="CODE"
                        ReadOnly="True" SortExpression="CODE" UniqueName="CODE">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DESC" HeaderText="DESCRIPTION" SortExpression="DESC"
                        UniqueName="DESC">
                    </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="WORDS" HeaderText="WORDS" SortExpression="WORDS"
                        UniqueName="WORDS">
                    </telerik:GridBoundColumn>
                </Columns>
                <EditFormSettings CaptionDataField="CODE" CaptionFormatString="Edit Company">
                    <EditColumn UniqueName="EditCommandColumn1">
                    </EditColumn>
                </EditFormSettings>
            </MasterTableView>
            <FilterMenu EnableTheming="True" Skin="Inox">
                <CollapseAnimation Duration="200" Type="OutQuint" />
            </FilterMenu>
        </telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Apr 2009, 09:33 AM
Hi Paul,

Give a try with the following approach and see whether it helps.

CS:
 
 
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
        if((e.Item is GridEditableItem)&&(e.Item.IsInEditMode)&&(!e.Item.OwnerTableView.IsItemInserted))  
        {  
            GridEditableItem editItem = (GridEditableItem)e.Item;  
            TableCell userNameCell = (TableCell)editItem["CODE"];  
            userNameCell.Enabled = false;  
            userNameCell.Visible = false;  
        }  
    }  


Thanks
Shinu.
Tags
Grid
Asked by
Paul Buxton
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or