The NavigateUrlFormat property of the SPMenuField allows you to specify a Url, which will be called if you click the field in a SPGridView.
1: SPMenuField colMenu = new SPMenuField();
2: colMenu.NavigateUrlFields = "WebUrl,AlertID,ListID";
3: colMenu.NavigateUrlFormat = "{0}/_layouts/SubEdit.aspx?Alert={1}&List={2}; 4: colMenu.TokenNameAndValueFields = "WEBURL=WebUrl,ALERTID=AlertID,LISTID=ListId";
With the TokenNameAndValueFields property, you map the grid columns to %xyz%.
If you want to use a JavaScript instead, you can do so:
1: MenuItemTemplate editAlertMenu = new MenuItemTemplate("Name", "imageUrl"); 2: editAlertMenu.ClientOnClickScript = "editAlertScript('%WEBURL%','%ALERTID%','%LISTID%');"; 3: alertListMenu.Controls.Add(editAlertMenu);
The trick is, that you have to put a ' around the variables.
The JavaScript would be something like
1: <script type="text/javascript">
2: function editAlertScript(weburl, alertid, listid){ 3: var url = weburl + '/_layouts/SubEdit.aspx?Alert=' + alertid;
4: if (listid.length > 0)
5: { url = url + '&List=' + listid; } 6: window.navigate(url);
7: }
8: </script>