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

[Solved] update/cancel in edit col

5 Answers 175 Views
Grid
This is a migrated thread and some comments may be shown as answers.
eric
Top achievements
Rank 1
eric asked on 11 Aug 2009, 10:35 PM
I am using a user control as my edit form in a grid and I wanted to know if it is possible to have an update and cancel button in the edit column when an item is in edit mode.  I know this is done in the inplace edit mode, and I want to mimic this functionality.  I don't want to have to place save and cancel buttons in my user control.  Thanks.

5 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 12 Aug 2009, 05:15 AM
Hello Eric,

You can add controls to your Edit column using the folliowing code:
aspx:
  <telerik:GridEditCommandColumn UniqueName="EditColumn">        
        </telerik:GridEditCommandColumn> 

c#:
 protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name == "Master"
        { 
            GridEditFormItem editItem = (GridEditFormItem)e.Item; 
            GridDataItem item = (GridDataItem)editItem.ParentItem; 
            item["EditColumn"].Controls.Clear(); 
            LinkButton link1 = new LinkButton(); 
            link1.CommandName = "Update"
            link1.Text = "Update"
            Label lbl = new Label(); 
            lbl.Text = "  "
            LinkButton link2 = new LinkButton(); 
            link2.CommandName = "Cancel"
            link2.Text = "Cancel"
            item["EditColumn"].Controls.AddAt(0, link1); 
            item["EditColumn"].Controls.AddAt(1, lbl); 
            item["EditColumn"].Controls.AddAt(2, link2);             
        } 
    } 

Thanks
Princy.
0
eric
Top achievements
Rank 1
answered on 12 Aug 2009, 11:43 PM

Princy, thank you the code works great, the only modification i made was to remove     " && e.Item.OwnerTableView.Name == "Master") "     from the if statement.  I am however getting some irregualr behavior in my update command function.  

e.item is not in edit mode when my update command function gets called.  Because of this I cannont correctly reference my user control as it returns null when i try to do ....... CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl)

Any thoughts?  Thanks again


 

 

 

Protected Sub rgGiveFeedback_UpdateCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgGiveFeedback.UpdateCommand  
 
Dim MyUserControl As UserControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl)  
 
Dim editControl As ucEditGiveFeedBack = CType(MyUserControl, ucEditGiveFeedBack)  
 
editControl.save()  
 
End Sub 
 



 

 

 

    Protected Sub rgGiveFeedback_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgGiveFeedback.ItemCreated  
        If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then 
            Dim editItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)  
            Dim item As GridDataItem = DirectCast(editItem.ParentItem, GridDataItem)  
            item("edit").Controls.Clear()  
            Dim link1 As New LinkButton()  
            link1.CommandName = "Update" 
            link1.Text = "Update" 
            Dim lbl As New Label()  
            lbl.Text = " " 
            Dim link2 As New LinkButton()  
            link2.CommandName = "Cancel" 
            link2.Text = "Cancel" 
            item("edit").Controls.AddAt(0, link1)  
            item("edit").Controls.AddAt(1, lbl)  
            item("edit").Controls.AddAt(2, link2)  
        End If 
    End Sub 



 

 

    <telerik:RadGrid ID="rgGiveFeedback" runat="server" Skin="Office2007" AllowPaging="false" 
        AutoGenerateColumns="false">  
        <HeaderContextMenu Skin="Office2007">  
            <CollapseAnimation Type="OutQuint" Duration="200" /> 
        </HeaderContextMenu> 
        <MasterTableView CommandItemDisplay="None" ShowHeader="false">  
            <EditFormSettings EditFormType="WebUserControl" UserControlName="~/UserControls/ucEditGiveFeedBack.ascx" /> 
            <NoRecordsTemplate> 
                There are no records to display.  
            </NoRecordsTemplate> 
            <Columns> 
                <telerik:GridEditCommandColumn EditText="Edit" UniqueName="edit" ButtonType="ImageButton" 
                CancelImageUrl="~/RadControls/Grid/Skins/Default/Cancel.gif" 
                InsertImageUrl="~/RadControls/Grid/Skins/Default/Insert.gif" 
                UpdateImageUrl="~/RadControls/Grid/Skins/Default/Update.gif" /> 
                <telerik:GridBoundColumn DataField="QuestionID" UniqueName="QuestionID" 
                    HeaderText="QuestionID" Visible="false">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="TitleWithNumber" UniqueName="TitleWithNumber" 
                    HeaderText="TitleWithNumber" Visible="true">  
                </telerik:GridBoundColumn> 
            </Columns> 
        </MasterTableView> 
    </telerik:RadGrid> 

0
eric
Top achievements
Rank 1
answered on 13 Aug 2009, 12:28 AM
when I said "e.item is not in edit mode when my update command function gets called."  I meant to say .... e.item.isineditmode is false, but e.edit is true
0
Princy
Top achievements
Rank 2
answered on 13 Aug 2009, 05:52 AM
Hello Eric,

You can access the UserCOntrol with some modification in your code, as shown below:
vb:
Protected Sub rgGiveFeedback_UpdateCommand(source As Object, e As Telerik.Web.UI.GridCommandEventArgs) 
 
    Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) 
    Dim MyUserControl As UserControl = DirectCast(item.EditFormItem.FindControl(GridEditFormItem.EditFormUserControlID), UserControl) 
 
    Dim editControl As ucEditGiveFeedBack = DirectCast(MyUserControl, ucEditGiveFeedBack) 
    editControl.save() 
End Sub 

Thanks
Princy.
0
eric
Top achievements
Rank 1
answered on 19 Aug 2009, 08:10 PM
Thanks for your help Princy.
Tags
Grid
Asked by
eric
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
eric
Top achievements
Rank 1
Share this question
or