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

When is Item in insert mode in IBindableTemplate

2 Answers 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pether Wiklander
Top achievements
Rank 2
Pether Wiklander asked on 12 Jan 2009, 02:26 PM
Hi,

Im building my own custom column by inheriting from IBindableTemplate. As suggested, I create the controls in the overridden InstantiateIn method. Now to the problem... I need to know if the controls should be created in "insert mode" or "edit mode". How can I do this?

public void InstantiateIn( Control container ) 
        { 
            switch( _templateType ) 
            { 
                case ListItemType.Header: 
                    break; 
                case ListItemType.Item: 
                    ImageButton editButton = new ImageButton 
                                             { 
                                                 ImageUrl = Images.EditIcon, 
                                                 CommandName = "Edit"
                                                 ToolTip = Dictionary.LocalizedString( Dictionary.Word.Edit ) 
                                             }; 
                    container.Controls.Add( editButton ); 
                     
                    ImageButton deleteButton = new ImageButton 
                                               { 
                                                   ImageUrl = Images.DeleteIcon, 
                                                   CommandName = "Delete"
                                                   ToolTip = Dictionary.LocalizedString( Dictionary.Word.Delete ) 
                                               }; 
                    deleteButton.Attributes.Add( "onclick", "javascript:return confirm('" + _confirmText + "');" ); 
                    container.Controls.Add( deleteButton ); 
                    break; 
                case ListItemType.EditItem: 
                    ImageButton updateButton = new ImageButton 
                                               { 
                                                   ImageUrl = Images.EditIcon, 
                                                   CommandName = "UpdateEdited"
                                                   ToolTip = Dictionary.LocalizedString( Dictionary.Word.Update ) 
                                               }; 
                    container.Controls.Add( updateButton ); 
 
                    ImageButton cancelButton = new ImageButton 
                                               { 
                                                   ImageUrl = Images.EditIcon, 
                                                   CommandName = "CancelAll"
                                                   ToolTip = Dictionary.LocalizedString( Dictionary.Word.Cancel ) 
                                               }; 
                    container.Controls.Add( cancelButton ); 
                    break; 
                case ListItemType.Footer: 
                    break; 
            } 
        } 

So... when the grid is in insert mode, I want the "edit" and "delete" buttons to change into "insert" and "cancel". Any suggestions?

// Pether

2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 15 Jan 2009, 09:52 AM
Hello Pether,

You can try check the NamingContainer of current control whether it is in edit or insert mode.
For example
public void InstantiateIn(Control container)  
    {  
        GridItem item = (GridItem)container.NamingContainer;  
        if (item is GridEditFormInsertItem)  
        {  
            //insert mode  
        }  
        else if (item is GridEditFormItem && item.IsInEditMode)  
        {  
            //edit mode  
        }  
    } 

I hope this helps.

Kind regards,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Pether Wiklander
Top achievements
Rank 2
answered on 15 Jan 2009, 01:47 PM
Hi,

It helped me but the solution was not totally correct. Thought that I might post the solution here for others:

if( container.NamingContainer is GridDataInsertItem ) 
    // Insert mode 
else  
    // Edit mode 

// Pether
Tags
Grid
Asked by
Pether Wiklander
Top achievements
Rank 2
Answers by
Nikolay Rusev
Telerik team
Pether Wiklander
Top achievements
Rank 2
Share this question
or