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

CreateColumnEditor is fired for an Insert or an Edit?

1 Answer 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fred
Top achievements
Rank 1
Fred asked on 06 Oct 2011, 07:53 PM
Hi!

I'm trying to do something.

I need to have different inline editor base on the type of edition...

It can be an insert or an edit.

I want to be able to have different ColumnEditor defined in the event CreateColumnEditor of the RadGrid depending on if it's edit mode or insert mode.

The event gives object but I have no clue if it is an insert or an edit.

Is there a way to identify if the event was fired for an insert or an edit?

Thanks!

protected void RadGrid_OnCreateColumnEditor(object sender, Telerik.Web.UI.GridCreateColumnEditorEventArgs e) 
        
            if (e.Column is GridBoundColumn) 
            
                if ((e.Column as GridBoundColumn).DataField == "UserValue") 
                
                    e.ColumnEditor = new NumericColumnEditor("UserValue"); 
                
                else if ((e.Column as GridBoundColumn).DataField == "UserId") 
                
                    e.ColumnEditor = new LabelColumnEditor("UserId"); 
                
                else if ((e.Column as GridBoundColumn).DataField == "UserName") 
                
                    e.ColumnEditor = new LabelColumnEditor("UserName"); 
                
            
        }

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 11 Oct 2011, 08:07 AM
Hi Fred,

To achieve the desired functionality you could try handling the RadGrid.ItemCommand and set a flag if the Edit command is fired or InitInsert command. Then into the RadGrid.CreateColumnEditor you could check this flag:
bool isEditColumnEditorCreated = false;
    void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.EditCommandName)
        {
            isEditColumnEditorCreated = true;
        }
        if (e.CommandName == RadGrid.PerformInsertCommandName)
        {
            isEditColumnEditorCreated = false;
        }
    }
 
    void RadGrid1_CreateColumnEditor(object sender, GridCreateColumnEditorEventArgs e)
    {
        if (isEditColumnEditorCreated)
        {
            //Edit
        }
        else
        {
            //Insert
        }
    }

Please give it try and let me know if you experience any problems.

Looking forward for your reply.

Greetings,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Fred
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or