簡體   English   中英

具有查詢字符串的超鏈接並在asp.net Datagrid中的新窗口中打開

[英]Hyperlink with query string and open in new window in asp.net Datagrid

首先,我可能已經在Stack OverFlow上搜索了有關我的問題的所有線程。 由於未找到任何預期的結果,因此我強迫自己發布此問題。

我的問題是:我在datagrid中使用超鏈接,並將datafield作為querystring傳遞,當單擊以下鏈接時,我希望彈出窗口在URL中帶有querystring的情況下打開。

<asp:HyperLink ID="lnkViewDoc" Text='View Document' NavigateUrl='<%# string.Format("javascript:window.open('ViewDoc.aspx?DocP={0}', 'MsgWindow','width=200,height=100')", Eval("vchDocPath")) %>' runat="server"></asp:HyperLink>

在上面的代碼中,我收到錯誤消息“服務器標記執行不正確。”。 誰能給我確切的密碼?


我嘗試了另一種格式。 在下面的代碼中,我沒有收到錯誤,但是當單擊鏈接時,什么都沒有發生,就像鏈接不可點擊一樣。

<asp:HyperLink ID="lnkViewDoc" Text='View Document' NavigateUrl='Javascript:void(window.open("<%# Eval("vchDocPath", "ViewDoc.aspx?DocP={0}") %>","mywindow","toolbar=0,width=500,height=500"))' runat="server"></asp:HyperLink>

PS:我從堆棧溢出和其他站點嘗試了許多其他格式,但是沒有運氣。

提前致謝。

這是一個將參數傳遞給javascript函數的示例html按鈕。

<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server">
            <Columns>
              <asp:TemplateField>
                 <ItemTemplate>
                    <button onclick='<%# "ShowWindow(\"" + "ViewDoc.aspx?DocP=" + Eval("vchDocPath") + "\")" %>'>View Document</button>
                 </ItemTemplate>
              </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>    

<script type="text/javascript">

    function ShowWindow(e) {
        window.open(e, "mywindow", "toolbar=0,width=500,height=500");
    }

</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM