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

Datafield in update and insert

5 Answers 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nizar
Top achievements
Rank 1
Nizar asked on 02 Jun 2011, 06:50 PM
Hello,

How can I make a datafield "edittable" on an insert call, but not on an update? I generate my table fine, and I use inline for editting mode. I display a name column, and a description column. When I click on update, I want only the description field to be edittable, but if I click on the add new record, I want both the name and description fields to be edittable. How can I accomplish this?

Thanks.

5 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Jun 2011, 07:35 PM
Hi,

u can set property in itemdataBound like...

<telerik:GridBoundColumn UniqueName="ColumnUniqueName">

private void RadGrid1_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e)
{
if(e.Item is GridEditFormItem && e.Item.IsInEditMode)
{
 if(e.Item.OwnerTableView.IsItemInserted)
 {
  //item is about to be inserted
   RadGrid1.MasterTableView.GetColumn("ColumnUniqueName").Visible = false;
   RadGrid1.MasterTableView.GetColumn("ColumnUniqueName2").ReadOnly= true;
 
 }
 else
 {
  //item is about to be edited
   RadGrid1.MasterTableView.GetColumn("ColumnUniqueName").Visible = true;
   RadGrid1.MasterTableView.GetColumn("ColumnUniqueName2").ReadOnly= false;
 
 }
}
}

Thanks,
Jayesh Goyani
0
Nizar
Top achievements
Rank 1
answered on 02 Jun 2011, 08:57 PM
Hi Jayesh,

Thanks for responding so promptly. However, I don't see, or don't have available, the "readOnly" attribute as in your code:

RadGrid1.MasterTableView.GetColumn("ColumnUniqueName2").ReadOnly= true;

I only see "visible" and "display". I also see there's a boolean "isEditable", but that basically just takes from the "readOnly" attribute in the <telerik:gridColumnBound> tag in the ASPX page. What you proposed in your code would be perfect, but I can't find the ".ReadOnly" portion.

Thanks.

nizar d.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Jun 2011, 06:26 AM
Hi,

sorry it was my mistake readonly option was not available.
you can use  "Visible" or "IsEditable".

like..
grdTablesandViews.MasterTableView.Columns.FindByUniqueName("ColumnUniqueName").Visible = false;


Thanks,
Jayesh Goyani
0
Princy
Top achievements
Rank 2
answered on 03 Jun 2011, 06:33 AM
Hello Nizar,

In order to make column editable on InsertCommand and disable the column in Edit mode, access the TextBox using the ColumnUniqueName and set ReadOnly as false.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {
           GridEditFormItem item = (GridEditFormItem)e.Item;
        TextBox txtbox=(TextBox)item["ColumnUniqueName"].Controls[0];
            txtbox.ReadOnly = false;
          }
}

Thanks,
Princy.
0
Nizar
Top achievements
Rank 1
answered on 03 Jun 2011, 05:32 PM
Hi Jayesh and Princy,

I appreciate your help on this, but this is what worked for me:

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        foreach (GridColumn col in RadGrid1.Columns)
        {
            if (col.ColumnType == "GridBoundColumn" && col.UniqueName == "routingPlanID")
            {
                if (e.CommandName == RadGrid.EditCommandName)
                {
                    (col as GridBoundColumn).ReadOnly = true;
                    col.Visible = true;
                }
                else
                {
                    (col as GridBoundColumn).ReadOnly = false;
                    col.Visible = true;
                }
            }
        }
    }

Again, thanks once more for your continued support. You guys are very helpful, and I've used many of your responses before with other users. Thanks!!!

nizar d.
Tags
Grid
Asked by
Nizar
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Nizar
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or