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

How can I distinguish edit and insert command on OnEditCommand Method

1 Answer 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Abhi Shinde
Top achievements
Rank 1
Abhi Shinde asked on 10 Nov 2010, 09:01 AM
Hi,
   I am using radgrid and edit form as a user control.

I want to find either user clicked on "Edit" or "add new record" link inside  "OnEditCommand Method".
 coz i want to hide insert button (which is present inside edit user control) when user clicks on "edit" link.
           and
hide update button (which is present inside edit user control) when user clicks on "add new record" link 

I used foll. code, but its not working correctly.
If condition is TRUE for both Edit and add clicks.

protected void rdgrid_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
           {
               UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
               ((Button)(userControl.FindControl("btnInsert") as Button)).Visible = false;
               ((Button)(userControl.FindControl("btnUpdate") as Button)).Visible = true;
           }
       }

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 10 Nov 2010, 10:06 AM
Hello Abhi,

Use the following condition to identify whether the grid is in edit or insert mode.

C#:
protected void rdgrid_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridEditFormItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted)
        //if the item is about to edit
       {
           GridEditFormItem insertItem = (GridEditFormItem)e.Item;
       }
       if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
       //if the item is about to insert
       {
           GridEditFormInsertItem insertItem=(GridEditFormInsertItem)e.Item;
       }
   }

Thanks,
Princy.
Tags
Grid
Asked by
Abhi Shinde
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or