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

[Solved] Launching PopUp EditForm from Custom Command

1 Answer 202 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bill Steamshovel
Top achievements
Rank 1
Bill Steamshovel asked on 24 Sep 2009, 12:58 AM

I bind a list of business objects to a radgrad and I have a different usercontrol for the adding and editing of the object. This works fine. Now I want to add a custom command (EndLife), so I thought I would simply add it to the ItemCommand handler to perform different logic on it. This is code I have below:

Protected Sub MilkCrateListView_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles MilkCrateListView.ItemCommand  
        If (e.CommandName = Telerik.Web.UI.RadGrid.InitInsertCommandName) Then 
            e.Item.OwnerTableView.EditFormSettings.UserControlName = "~/uc/AddMilkCrate.ascx" 
            e.Canceled = True 
            rgParts.EditIndexes.Clear()  
            e.Item.OwnerTableView.InsertItem()  
        ElseIf (e.CommandName = Telerik.Web.UI.RadGrid.EditCommandName) Then 
            e.Item.OwnerTableView.EditFormSettings.UserControlName = "~/uc/EditMilkCrate.ascx" 
            e.Item.OwnerTableView.IsItemInserted = False 
        ElseIf (e.CommandName = MilkCrateView.EndLifeCommandName) Then 
            e.Item.Edit = True 
            e.Item.OwnerTableView.EditFormSettings.UserControlName = "~/uc/EndLifeMilkCrate.ascx" 
            e.Item.OwnerTableView.IsItemInserted = False 
        End If 
    End Sub 

The first time I click EndLife, the line item within the RadGrid is highlighted and put into EditMode, but the PopUp doesn't launched until I click EndLife. This is an issue itself, but because of this, the datagrid doesn't rebind inbetween calls, meaning the UserControl receives a null DataItem.

How can I get the PopUp to fire immediately? Would I fire an EditCommand from within the ItemCommand handler? If so, can someone give me an example of doing this?  

If not, how would I go about acheiving the functionality desired?

EDIT: Instead of using a Custom Command Name, I reused the CommandName Edit and added a CommandArgument 

ASP.NET
<telerik:GridButtonColumn ButtonType="LinkButton" CommandName="Edit" CommandArgument="Edit" HeaderText="Edit" Text="Edit" ></telerik:GridButtonColumn>                    
<telerik:GridButtonColumn ButtonType="LinkButton" CommandName="Edit" CommandArgument="Remove" HeaderText="Remove" Text="Remove"></telerik:GridButtonColumn> 

VB.NET
Protected Sub MilkCrateListView_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles MilkCrateListView.ItemCommand     
   If (e.CommandName = Telerik.Web.UI.RadGrid.InitInsertCommandName) Then    
      e.Item.OwnerTableView.EditFormSettings.UserControlName = "~/uc/AddMilkCrate.ascx"    
      e.Canceled = True    
      rgParts.EditIndexes.Clear()     
      e.Item.OwnerTableView.InsertItem()     
   ElseIf (e.CommandName = Telerik.Web.UI.RadGrid.EditCommandName) Then    
      e.Item.OwnerTableView.IsItemInserted = False    
      If (e.CommandArgument = MilkCrateView.EndLife) Then    
         e.Item.OwnerTableView.EditFormSettings.UserControlName = "~/uc/EndLifeMilkCrate.ascx"    
      Else 
         e.Item.OwnerTableView.EditFormSettings.UserControlName = "~/uc/EditMilkCrate.ascx"    
      End If    
   End If    
End Sub    
 


 

1 Answer, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 25 Sep 2009, 02:39 PM
Hi Bill,

To achieve the described functionality I recommend you to use the FireCommandEvent(eventName, eventArgs) method and call it for the particular item.

For additional information you may take a look at the How to fire command events from code help topic.

Best wishes,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Bill Steamshovel
Top achievements
Rank 1
Answers by
Mira
Telerik team
Share this question
or