[英]Open Modal Box from link in SPGridView using JavaScript
I have a SPGridView in SharePoint 2010 Foundation containing announcements from subsites. 我在SharePoint 2010 Foundation中有一个SPGridView,其中包含来自子网站的公告。 I have only one column, a HyperLinkField that displays the title of the announcement and links to the dispform of the item. 我只有一列,即HyperLinkField,它显示公告的标题并链接到该项目的显示。
The data is collected using a SPDataSiteQuery. 使用SPDataSiteQuery收集数据。
What I want is the link to run a JavaScript, added on the page with a Content Editor Web Part, that will open a Modal Box and in it display the dispform. 我想要的是运行JavaScript的链接,该链接添加到页面上的内容编辑器Web部件中,这将打开一个模式框并在其中显示dispform。
My code currently looks like below and succentsfully opens the dispform in the same window but I now want it to call the JavaScript. 我的代码当前如下所示,并成功在同一窗口中打开了dispform,但现在我希望它调用JavaScript。
HyperLinkField hyperFieldTask = new HyperLinkField();
hyperFieldTask.HeaderText = "News";
hyperFieldTask.DataTextField = "Title";
string[] itemUrl = { "FileDirRef" };
hyperFieldTask.DataNavigateUrlFields = itemUrl;
hyperFieldTask.DataNavigateUrlFormatString = "";
hyperFieldTask.SortExpression = "Title";
this.grid.Columns.Add(hyperFieldTask);
I have tried several solutions but all I get is an inactive link. 我已经尝试了几种解决方案,但是得到的只是一个无效链接。
hyperFieldTask.DataNavigateUrlFormatString = "JavaScript:ShowDialog('url')";
hyperFieldTask.DataNavigateUrlFields = "JavaScript:ShowDialog('url')";
Nothing I do seems to work. 我似乎无济于事。
Have I missed something obvious? 我错过了明显的事情吗?
Thanks for helping. 感谢您的帮助。
EDIT: 编辑:
I tried using NavigateUrl and it does indeed call the JavaScript. 我尝试使用NavigateUrl,它确实调用了JavaScript。
hyperFieldNews.NavigateUrl = "javascript:ShowDialog('http://www.google.com', '600')";
The next step is now to instead of using www.google.com as url I want to use the value of "FileDirRef". 现在,下一步是我要使用“ FileDirRef”的值,而不是使用www.google.com作为URL。
add the following JavaScript function: 添加以下JavaScript函数:
<script type="text/javascript"> function ModalPopup(url, title) { var options = SP.UI.$create_DialogOptions(); options.url = url; options.title = title; options.dialogReturnValueCallback = function () { SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK); }; SP.UI.ModalDialog.showModalDialog(options); } </script>
now you can create a link and call the function: 现在您可以创建一个链接并调用该函数:
HyperLink hyper1 = new HyperLink(); string popUpPageUrl = "javascript:ModalPopup('" + url + "','Display Item')"; hyper1.NavigateUrl = popUpPageUrl; hyper1.Text = "News";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.