【问题标题】:To open a popup window on clicking link button in grid view在网格视图中单击链接按钮时打开弹出窗口
【发布时间】:2014-05-02 11:15:21
【问题描述】:

在下面的代码中,我在网格视图中有一个网格视图,当我单击链接按钮时,我有一个链接按钮,它应该会打开一个弹出窗口。请帮我这样做。

<asp:TemplateField HeaderText="Edit" itemstyle-width="150px">
                            <ItemTemplate>
                                <asp:LinkButton ID="btnEdit" runat="server" CommandName="Edit" Text="Edit" CausesValidation="false"/>
                            </ItemTemplate>    
                        </asp:TemplateField>  

代码隐藏:

if (e.CommandName.Equals("Edit"))
 {

                    LinkButton btnView = (LinkButton)e.CommandSource;
 Response.Redirect("NewDocument.aspx?DID=" + lblDocumentID.Text.ToString(), true);
                } 

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    请尝试:

    if (e.CommandName.Equals("Edit"))
    {
        string QueryString="val";
        Page.ClientScript.RegisterStartupScript(GetType(), "", "window.open('Page.aspx?QS=" + QueryString + "','','width=500,height=500');"", true);
    } 
    

    【讨论】:

    • 如何在这个中传递查询字符串
    【解决方案2】:

    试试这个..

    if (e.CommandName.Equals("Edit"))
    {
        ScriptManager.RegisterStartupScript(this, this.GetType(), "onclick", "javascript:window.open(
        'NewDocument.aspx?DID="+lblDocumentID.Text+"','_blank','height=600px,width=600px,scrollbars=1');", true);
    } 
    

    【讨论】:

    • 如何在这个中传递查询字符串
    【解决方案3】:
    <div>
        <asp:GridView ID="gvDemo" runat="server" AutoGenerateColumns="false">
            <Columns>
                <asp:BoundField DataField="Name" HeaderText="Name" />
                <asp:TemplateField HeaderText="">
                    <ItemTemplate>
                        <a href="#" onclick='openWindow("<%# Eval("Code") %>");'>View Details</a>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    <script type="text/javascript">
        function openWindow(code) {
            window.open('page.aspx?Code=' + code, 'open_window', ' width=640, height=480, left=0, top=0');
        }
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-31
      • 1970-01-01
      相关资源
      最近更新 更多