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

Allow insert but not update

2 Answers 167 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zac
Top achievements
Rank 1
Zac asked on 19 Mar 2009, 07:54 PM
I'm using automatic inserts/updates with a grid bound to an ObjectContainerDataSource.  Some of the columns are marked as readonly in the grid and should not be updated.  However, on an insert, users should specify values for these columns.  Is there an easy way to mark a column as read-only for updates but read-write for inserts?

Thanks,

Zac

2 Answers, 1 is accepted

Sort by
0
Zac
Top achievements
Rank 1
answered on 19 Mar 2009, 10:28 PM
As an alternate approach, I tried removing the ReadOnly attribute from the columns and then disabling them when in edit mode.  Just to clarify - the user should be able to specify values only on insert, but not on update.  But this isn't working.  The columns are still editable on update.  Here's a sample:

 void Grid_ItemCommand(object source, GridCommandEventArgs e)
        {
            if( e.CommandName == RadGrid.EditCommandName)
            {
                GridEditableItem gridRow = e.Item as GridEditableItem;

                // Username cannot be changed.
                TableCell userNameCell = gridRow["UserName"];
                userNameCell.Enabled = false;
                userNameCell.Visible = false;
            }
        }
0
Accepted
Shinu
Top achievements
Rank 2
answered on 20 Mar 2009, 09:13 AM
Hi Zac,

You can try the following approach to hide/disable  the column when the Grid is in edit mode and enable/show them when the Grid is insert mode.

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["ProductName"]; 
            userNameCell.Enabled = false
            userNameCell.Visible = false
        } 
    } 

Thanks
Shinu.

Tags
Grid
Asked by
Zac
Top achievements
Rank 1
Answers by
Zac
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or