C# GridView点击某列打开新浏览器窗口

时间:2022-04-16 08:28:59

C# GridView点击某列打开新窗口的方式:

(1)打开浏览器新窗口:蓝色部分 通过超链接。

(2)打开模式化窗口:通过OnRowCommand事件,弹出模式化窗口。

具体如下:

<asp:GridView ID="gvAssess" runat="server" AutoGenerateColumns="False" SkinID="gridview"
                                OnRowCommand="gvAssess_RowCommand" CssClass="maingrid_text"  OnRowCreated="gvAssess_RowCreated">
                                <HeaderStyle HorizontalAlign="Center" />
                                <RowStyle HorizontalAlign="Center" />
                                <Columns>
                                    <asp:BoundField DataField="PBHD_ID" HeaderText="评价活动编号" />
                                    <asp:BoundField DataField="HD_NAME" HeaderText="活动名称" />
                                       <asp:TemplateField HeaderText="编辑">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkbtnDelete" runat="server" CommandArgument='<%# Eval("PBHD_ID") %>'
                                                CommandName="Edt" >编辑</asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="计算分数">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkbtnScore" runat="server" CommandArgument='<%#Eval("PBHD_ID") %>'
                                                CommandName="Score">计算分数</asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>

<asp:TemplateField HeaderText="打分">
                                        <ItemTemplate>

<%--C# GridView点击某列打开新浏览器窗口  传多个参数 --%>
                                             <a href="Grade.aspx?PBHD_ID=<%#Eval("PBHD_ID") %>" target="_blank">打分</a>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="查看">
                                        <ItemTemplate>

<%-- C# GridView点击某列打开新浏览器窗口  传多个参数 --%>
                                         <a href="Top.aspx?type=<%#Eval("ZB_TYPE") %>&pbhd=<%#Eval("PBHD_ID") %>" target="_blank">查看</a>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>

====后台弹出窗口:

//gridview数据按钮操作事件
    protected void gvAssess_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //编辑 传活动类型、ID、编辑

if (e.CommandName == "Edt")
        {
            ScriptManager.RegisterStartupScript(this.Page, typeof(string), "", "<script>var result;result = window.showModalDialog('AddAssessExercise.aspx?TYPE_ADD=Edt&TYPE=" + Server.UrlEncode(ViewState["TYPE"].ToString()) + "&PBHD_ID=" + Server.UrlEncode(e.CommandArgument.ToString()) + "','','dialogHeight:480px; dialogWidth:800px; dialogColor:red;status:no');if(result == '1' ) {document.getElementById( 'btnPackAgeF').click();}</script>", false);
            return;
        }

}