Passing table context to a menu item context in EP

Another small and easy item I always spend several minutes to recall when doing EP development, is setting a MenuItem's MenuItemContext with the current's form TableContext (taken from the CurrentRow property).

 So, the code snippet:


 a) registering the EventHandler in the Page_Load or PreRender:

        this.MainActionPane.SetMenuItemProperties += new EventHandler<SetMenuItemPropertiesEventArgs>(MainActionPane_SetMenuItemProperties);

b) adding the code to do our task:

    void MainActionPane_SetMenuItemProperties(object sender, SetMenuItemPropertiesEventArgs e)
    {
        switch (e.MenuItem.MenuItemAOTName.ToLower())
        {
            case "ourmenuitem":
                if (this.CurrentRow != null && this.CurrentRow.GetRecord() != null)
                {
                    ((AxUrlMenuItem)e.MenuItem).MenuItemContext = AxTableContext.Create((IAxTableRowKey)AxTableDataKey.Create(this.CurrentRow.GetRecord(), null));
                }
                break;
        }
    }

2 comments:

  1. Hi Iulian,
    Can you please help me to fix the following issue:
    I have a form on EP where two of the columns are AxHyperLinkBoundField, something like this:



    So I linked the same table from DataSet to both of these AxHyperLinkBoundField
    In C# I’m trying to pass the current raw to each of my urlMenuItems (MI_1SSRS and MI_2SSRS),
    Where MI_1SSRS – calls SSRSReport1 and MI_2SSRS – calls SSRSReport2.
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    this.AssignMenuItemProperties();
    }
    }

    protected void AssignMenuItemProperties()
    {
    AxUrlMenuItem urlMenuItem1 = new AxUrlMenuItem("MI_1SSRS");

    AxUrlMenuItem urlMenuItem2 = new AxUrlMenuItem("MI_2SSRS");

    if (CurrentRow != null)
    {
    urlMenuItem1.MenuItemContext = AxTableContext.Create(CurrentRow.GetDefaultTableDataKey(CurrentRow.DataSetView.Metadata.RootDataSource));

    urlMenuItem2.MenuItemContext = AxTableContext.Create(CurrentRow.GetDefaultTableDataKey(CurrentRow.DataSetView.Metadata.RootDataSource));
    }

    }
    The problem is that in this case (as described above) no matter which AxHyperLinkBoundField I’m calling but the same SSRSReport2 is invoked.
    If I replace these lines of code like below (I’ve putted line with MI_2SSRS above the line with MI_1SSRS), the SSRSReport1 is invoked.
    AxUrlMenuItem urlMenuItem2 = new AxUrlMenuItem("MI_2SSRS");
    AxUrlMenuItem urlMenuItem1 = new AxUrlMenuItem("MI_1SSRS");

    So, is there are any way to pass the same table to two different AxUrlMenuItem’s

    ReplyDelete
  2. Iulian, I apologize for the disturbance, I’ve already fixed it (the only thing I have to do – is to reopen the EP page )) . Thank you

    ReplyDelete