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

Inserting but insert area doesn't vanish

3 Answers 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chad Johnson
Top achievements
Rank 1
Chad Johnson asked on 01 Oct 2008, 06:39 PM
Greetings,

Ok, so I'm doing an insert into my grid via itemcommand, and here is the code.

case "PerformInsert":  
                    rgdStatusList.Columns.FindByUniqueName("Active").Visible = true;  
                    rgdStatusList.Columns.FindByUniqueName("Archived").Visible = false;  
                    AddStatus(e);  
                    break;  
 
protected void AddStatus(Telerik.Web.UI.GridCommandEventArgs e)  
        {  
            Telerik.Web.UI.GridEditableItem insertItem = e.Item.OwnerTableView.GetInsertItem();  
            //e.Item as Telerik.Web.UI.GridEditableItem;  
            Status mStatus = new Status();  
            AdminManager mAdminManager = new AdminManager();  
 
            //Pull in all needed info to create a new record in the database.  
            mStatus.StatusDescription = (insertItem["StatusDescription"].Controls[0] as TextBox).Text;  
            mStatus.Active = (insertItem["Archived"].Controls[0] as CheckBox).Checked;  
            mStatus.CommunityID = ParentKNPage.CoPID;  
 
            try  
            {  
                mAdminManager.InsertStatus(mStatus);  
            }  
            catch (Exception ex)  
            {  
                rgdStatusList.Controls.Add(new LiteralControl("Unable to insert Status.  Reason: " + ex.Message));  
            }  
        } 

In there, my mAdminManager.InsertStatus(mStatus) does add the data into my database, and once the page refreshes, the grid rebinds and displays the data.  The problem is, once the page does it's postback, the insert textbox is still visible.  Is there a way to kick the grid out of insert mode?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Chad Johnson
Top achievements
Rank 1
answered on 02 Oct 2008, 06:27 PM
Ok, here is an update on this.  I decided to move some things around to try something new.  Instead of using ItemCommand, I am now using the OnInsertCommand functionality of the grid.  This works and all, but like with my last piece of code, I'm having the same difficulty where upon my grid finishing it's insert, it remains in insert.  My suspicion is that it has to deal with e.Item.OwnerTableView.GetInsertItem(), since this never happened before.  Anyways, the two commented lines at the top are ways I tried to do this before, but failed due to a conversion error.

protected void rgdStatusList_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)  
        {  
            //Telerik.Web.UI.GridEditFormInsertItem insertItem = (Telerik.Web.UI.GridEditFormInsertItem)e.Item;  
            //Telerik.Web.UI.GridEditableItem insertItem = (Telerik.Web.UI.GridEditableItem)e.Item;  
            Telerik.Web.UI.GridEditableItem insertItem = e.Item.OwnerTableView.GetInsertItem();  
            Status mStatus = new Status();  
            AdminManager mAdminManager = new AdminManager();  
 
            //Pull in all needed info to create a new record in the database.  
            mStatus.StatusDescription = (insertItem["StatusDescription"].Controls[0] as TextBox).Text;  
            mStatus.Active = (insertItem["Archived"].Controls[0] as CheckBox).Checked;  
            mStatus.CommunityID = ParentKNPage.CoPID;  
 
            try 
            {  
                mAdminManager.InsertStatus(mStatus);  
            }  
            catch (Exception ex)  
            {  
                rgdStatusList.Controls.Add(new LiteralControl("Unable to insert Status.  Reason: " + ex.Message));  
            }  
        } 

If anyone sees anything glaring, please let me know.  I need to figure out how to kick this grid out of insert upon it finishing with it's add to the db.  Thanks a bunch.
0
Princy
Top achievements
Rank 2
answered on 03 Oct 2008, 07:36 AM
Hello Chad,

Have you set AllowAutomaticInserts to True? If so, try setting it to false and then the Insert Form should dissappear after an item is inserted. If not, you can try the following snippet of code to close the insert form on inserting an item.
cs:
  RadGrid1.MasterTableView.IsItemInserted = false

Thanks
Princy.
0
Chad Johnson
Top achievements
Rank 1
answered on 03 Oct 2008, 01:07 PM
Thanks for your help, but I came up with that solution, with the help of a coworker, last night, and it works beautifully now.  Thanks again.
Tags
Grid
Asked by
Chad Johnson
Top achievements
Rank 1
Answers by
Chad Johnson
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or