HyperLinkfidld和HyperLink弹窗不同解决方案
忙了一夜 翻了各种资料,发现还是老外的好用,或许国内以前同行写的内容老套了 最后折腾死我了
关于在GridView 里面添加 链接弹出窗口的问题,把网上的资料全部测试一边,然后总结下……做个Mark,下面提供几种方法参考,如果有调试通过的
说下环境和通过的方法。我的环境是VS2008.
1.利用JS弹窗,在NavigaterUrl添加事件,但这个只适合在HyperLink,并且调试过后,无法弹窗
<script type="text/javascript" language="javascript"> var newwindow; function popupstatic(url) { newwindow=window.open(url,'name','height=400,width=400'); if (window.focus) {newwindow.focus()} } </script>
<asp:TemplateField> <ItemTemplate> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("devicelocation", "javascript:popupstatic('UpdateAddress.aspx?DeviceLocation={0}')") %>' Target="_search" Text='<%# Eval("devicelocation", "Update") %>'></asp:HyperLink> </ItemTemplate> </asp:TemplateField>
2.这个是方法是网上资料的不知道残害多少新手,下面这段代码大部分人都搜到过,var win中间有间隔 只是定义个变量,就算这段JS是正确的,
但在VS2008调试后 点击链接还是没反应,略过。此方法只适合Hyperlink 也有可能无效
<asp:HyperLinkColumn DataNavigateUrlField="EmployeeID"
DataNavigateUrlFormatString="javascript:var win=window.open('detail.aspx?ID={0}',null,'width=300,height=200');window.Close();" DataTextField="LastName" HeaderText="LastName"></asp:HyperLinkColumn>
3.下面方法利用JQ的方式去调用跳窗,我顺便修改了下,这个只是弹出提示窗口,我要的效果是弹出一个窗口,相当于一个层,不需要用target=_blank这样的
在新窗口或者子窗口打开。
<script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $(".classid").click(function () { if (!confirm("是否操作此数据?")) { return false; } else { return true; } }); }); </script>
----------------------------修改利用JSON 参数 var index=0; var json = { "oo": [ { "url": "xx.aspx", "parm": "dialogHeight:600px;dialogWidth:700px;status:no;help:no;scroll:no" }] }; if (index == 0) { var result = window.showModalDialog(json.oo[index].url, window, json.oo[index].parm); } else { return false; }
<asp:HyperLinkField DataNavigateUrlFields="ScrewPumpWellID" DataNavigateUrlFormatString="SWBaseInfoForm.aspx?action=edit&ScrewPumpWellID={0}" HeaderText="删除" ControlStyle-CssClass="classid" Text="<img border=0 src=../images/Edit.gif />"> <ItemStyle Width="30px" /> </asp:HyperLinkField>
4.直接增加A标签,调用window.open的方式。这个是最方便也最易懂,后面穿了3个参数过去,包括弹出框局中。
<asp:TemplateField HeaderText="上传地址"> <ItemTemplate> <a href=# onclick='javascript:window.open("SelMap.aspx?txm=<%# Eval("GPSAddress") %>&xx=<%# Eval("GPSJINDU") %>&yy=<%# Eval("GPSWEIDU") %>",
null,"height=340px,width=520px,top="+(screen.height-340)/2+",left="+(screen.width-520)/2+",toolbar=no,menubar=no,location=no");' ><%# Eval("GPSAddress")%></a> </ItemTemplate> </asp:TemplateField>
最后有恶心的事情出现了,兼容性,方法4在IE6 7 下没问题 在IE8就不支持弹出的是新页面,最后没辙修改
还有在showModalDialog传参中文解码问题 利用encodeURIComponent 传参过去在解码
<asp:TemplateField HeaderText="上传地址"> <ItemTemplate> <a href=# onclick='javascript:window.showModalDialog("SelMap.aspx?txm="+encodeURIComponent("<%# Eval("GPSAddress")%>")+"&xx=<%# Eval("GPSJINDU") %>&yy=<%# Eval("GPSWEIDU") %>",null,"dialogHeight:340px;dialogWidth:520px;status:no;help:no;scroll:no");' ><%# Eval("GPSAddress")%></a> </ItemTemplate> </asp:TemplateField>
算是搞定了。这问题忙活死我了。。。。。。。。。。。。。。 有好方法的可以提供参考 这些都是我半天屁颠屁颠总结出来的
反正没有最好只有更好,后期可以考虑用JQ弹出层 但在GV里面获取参数是个问题 有点麻烦。。。。。。。