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 Object, ByVal 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 Object, ByVal 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 |