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

[Solved] Attaching Context Menu to RadGrid Row

4 Answers 230 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raul
Top achievements
Rank 1
Raul asked on 24 Jul 2013, 04:27 PM
I want to attach a context menu to each radgrid row runtime, as each row may have a different context menu.  I don't want to hard code the menu items in the context menu.

I am having a hard time figuring out how to do this.

Here is the code.

 Dim rmi3 As New RadMenuItem()

                Dim rcm3 As New RadContextMenu()

  Dim editZone As ContextMenuControlTarget = New Telerik.Web.UI.ContextMenuControlTarget()

                rmi3.Text = "Preparer"

                rmi3.Value = "1"

                rcm3.ID = "Role" & i

                rcm3.Items.Add(rmi3)

                Dim rmi4 As New RadMenuItem()

                rmi4.Text = "Reviewer"

                rmi4.Value = "2"

                rcm3.ID = "Role" & i

                rcm3.Items.Add(rmi4)

                Dim rmi5 As New RadMenuItem()

                rmi5.Text = "View PDF"

                rmi5.Value = "3"

                rcm3.ID = "Role" & i

                rcm3.Items.Add(rmi5)

                editZone.ControlID = row.dataitem("usqnumber")

                rcm3.Targets.Add(editZone)

                Me.Controls.Add(rcm3)

4 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 29 Jul 2013, 08:29 AM
Hello,

There should be no problem achieving your goal. You could check this help topic how to use row context menu with hard-coded items. Once you have this version working you could remove the hard-coded items and create them in the code-behind as explained in this help topic.

Regards,
Andrey
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Raul
Top achievements
Rank 1
answered on 31 Jul 2013, 03:26 PM
Thank you for the response.  What I need is to know how to attach the context menu to the gridview row.  I know how to create it on  a text box, etc. but not on a radgrid control.  I want to attach it to a single column on each gridview row.
0
Raul
Top achievements
Rank 1
answered on 31 Jul 2013, 03:41 PM
Here is the full set of code that i am working with

For Each row In radgrid1.Items

            ds2 = usqhelper.GetUserRole(snlid, facilityid, 1)

            If ds2.Tables(0).Rows.Count > 0 Then

                For Each row2 In ds2.Tables(0).Rows

                    roleid = row2("roleid")

                Next

            End If

            statusid = usqhelper.GetStatusID(row.dataitem("status"))

            If statusid = 4 Then

                Dim rmi As New RadMenuItem()

                Dim rcm As New RadContextMenu()

                Dim editZone As ContextMenuControlTarget = New Telerik.Web.UI.ContextMenuControlTarget()

                rmi.Text = "View PDF"

                rmi.Value = "1"

                rcm.ID = "Role" & i

                rcm.Items.Add(rmi)

                editZone.ControlID = row.dataitem("usqnumber") & i

                rcm.Targets.Add(editZone)

                Me.Controls.Add(rcm)

            ElseIf ((statusid <= 3) And roleid <= 3) Then

                Dim rmi1 As New RadMenuItem()

                Dim rcm1 As New RadContextMenu()

                Dim editZone As ContextMenuControlTarget = New Telerik.Web.UI.ContextMenuControlTarget()

                rmi1.Text = "Preparer"

                rmi1.Value = "1"

                rcm1.ID = "Role" & i

                rcm1.Items.Add(rmi1)

                Dim rmi2 As New RadMenuItem()

                rmi2.Text = "View PDF"

                rmi2.Value = "2"

                rcm1.ID = "Role" & i

                rcm1.Items.Add(rmi2)

                editZone.ControlID = row.dataitem("usqnumber") & i

                rcm1.Targets.Add(editZone)

                Me.Controls.Add(rcm1)

ElseIf (roleid = 2 Or roleid = 3) And statusid = 2 And Not (ispreparer) = usqhelper.DetermineIfPreparer(row.dataitem("Preparerid"), row.dataitem("usqid")) Then

                Dim rmi3 As New RadMenuItem()

                Dim rcm3 As New RadContextMenu()

                Dim editZone As ContextMenuControlTarget = New                    Telerik.Web.UI.ContextMenuControlTarget()

                rmi3.Text = "Preparer"

                rmi3.Value = "1"

                rcm3.ID = "Role" & i

                rcm3.Items.Add(rmi3)

                Dim rmi4 As New RadMenuItem()

                rmi4.Text = "Reviewer"

                rmi4.Value = "2"

                rcm3.ID = "Role" & i

                rcm3.Items.Add(rmi4)

                Dim rmi5 As New RadMenuItem()

                rmi5.Text = "View PDF"

                rmi5.Value = "3"

                rcm3.ID = "Role" & i

                rcm3.Items.Add(rmi5)

                editZone.ControlID = row.dataitem("usqnumber")

                rcm3.Targets.Add(editZone)

                Me.Controls.Add(rcm3)

            End If

           

        

            i = i + 1

        Next


 

0
Andrey
Telerik team
answered on 05 Aug 2013, 10:51 AM
Hello,

If you check again the help topic from the previous reply you would see that the menu is not attached to each row but it is displayed using the RowContextMenu client-side event. This event gives information on which row the user has clicked and thus helps you to show the menu at the correct position.

You could check on which cell the user has clicked and if it is not from the column you want you won't show the menu.

On the server-side you will only construct the menu items dynamically and then you will show the menu on the client-side.

I hope the provided information helps.

Regards,
Andrey
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Raul
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Raul
Top achievements
Rank 1
Share this question
or