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

[Solved] Two update bottons for edit form

3 Answers 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Heinz
Top achievements
Rank 1
Heinz asked on 04 Jun 2009, 12:54 PM
Hi,
is it possible to work in an edit form with two update buttons? One should update form values to database and keep in edit mode, the other should update and close edit mode. I did some trials with "KeepInEditMode" but without success.
Maybe there is a sample available?
Thanks for feedback and Regards
Heinz
p.s. of course title should be "buttons"

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Jun 2009, 01:45 PM
Hi Heinz,

You can use place the two buttons in FormTemplate of RadGrid as shown below.

ASPX:
 
<telerik:radgrid id="RadGrid1" runat="server" allowpaging="True" datasourceid="SqlDataSource1" OnItemCommand="RadGrid1_ItemCommand">  
<MasterTableView DataSourceID="SqlDataSource1" EditMode="EditForms" > 
<EditFormSettings EditColumn-ButtonType="PushButton" EditFormType="Template">  
<FormTemplate> 
    <asp:Button ID="button" runat="server" Text="Update and Close" CommandName="Update" /> <br /> 
    <asp:Button ID="button1" runat="server" Text="Update" CommandName="UpdateClose"  /> 
       . . .  
</FormTemplate> 
</EditFormSettings> 
<Columns> 
 . . .  
</Columns> 
</MasterTableView> 
</telerik:radgrid> 

CS:
 
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
{  
    if (e.CommandName == "UpdateClose")  
    {  
        //update query  
        e.Canceled = true;  
    }  

Thanks,
Princy.
0
Heinz
Top achievements
Rank 1
answered on 09 Jul 2009, 04:34 PM
Hi,
I have still a problem with this stuff. Button "update" should update to database and close editform. Button "UpdateKeepEdit" should update to database and keep in edit mode. I tried like suggested but didn't get "e.Canceled = True" to work. I found a solution with "editedItem.Edit = False" like shown in the code. But I am wondering why e.Canceled won't work. Here is the code from ItemCommand.
Thanks
Heinz

    Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand 
        Dim tmpBool As Boolean = False 
 
        If ((e.CommandName = "Update"Or (e.CommandName = "UpdateKeepEdit")) Then 
            Dim editedItem As GridEditableItem = DirectCast(TryCast((e.CommandSource), Button).NamingContainer, GridEditableItem) 
            Dim tmpArticleID As Integer = Convert.ToInt32(editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("id").ToString()) 
            Dim tmpText As String = (TryCast(editedItem.FindControl("Text1"), RadEditor)).Content 
 
            Write2DB(tmpArticleID, tmpText) 
 
            If e.CommandName = "Update" Then 
                'update query   
                'e.Canceled = True 
                editedItem.Edit = False 
            Else 
                tmpBool = False 
                'e.Canceled = False 
 
            End If 
        End If 
         
    End Sub 
0
Tsvetoslav
Telerik team
answered on 13 Jul 2009, 12:12 PM
Hello Heinz,

Canceling the ItemCommand event will prevent the grid's automatic operations from being executed. For example, if you need to use automatic inserts and you trigger and insert command, in case you cancel the event no item will be inserted. When manually handing the update operation in code behind there are two possible ways for closing the edit form:

- the first is the one you have already implemented.

- the second: RadGrid1.MasterTableView.ClearEditItems();

I hope this information helps.

Best Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Heinz
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Heinz
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or