C# 从模板字段内的按钮触发GridView RowCommand事件-C

C# 从模板字段内的按钮触发GridView RowCommand事件-C,c#,gridview,bootstrap-modal,rowcommand,C#,Gridview,Bootstrap Modal,Rowcommand,所以我有一个GridView摘要,它包含一个模板字段,在btnOpen中有一个按钮。此按钮用于根据gvSummary中的行信息在模式窗口中打开第二个GridView gvDetail 我遇到的问题是,我似乎无法通过单击按钮btnOpen来执行gvSummary_row命令中的代码。我可以从中执行代码,但这不会打开第二个GridView 这是我的密码: <asp:GridView ID="gvSummary" runat="server" DataSourceID="SqlgvSummary

所以我有一个GridView摘要,它包含一个模板字段,在btnOpen中有一个按钮。此按钮用于根据gvSummary中的行信息在模式窗口中打开第二个GridView gvDetail

我遇到的问题是,我似乎无法通过单击按钮btnOpen来执行gvSummary_row命令中的代码。我可以从中执行代码,但这不会打开第二个GridView

这是我的密码:

<asp:GridView ID="gvSummary" runat="server" DataSourceID="SqlgvSummary" AutoGenerateColumns="false"
OnRowDataBound="gvSummary_RowDataBound" OnRowCommand="gvSummary_RowCommand" CssClass="table table-hover table-bordered" EmptyDataText="No data to display." >
    <Columns>
        <asp:BoundField DataField="ClientRef" HeaderText="Reference No."/>
        <asp:BoundField DataField="InsertedWhen" HeaderText="Transaction Date" DataFormatString="{0:dd-MM-yyyy}" />
        <asp:BoundField DataField="Commodity" HeaderText="Commodity" />
        <asp:BoundField DataField="StartDate" HeaderText="Settlement Date" DataFormatString="{0:dd-MM-yyyy}" />
        <asp:BoundField DataField="EndDate" HeaderText="Delivery Date" DataFormatString="{0:dd-MM-yyyy}" />
        <asp:BoundField DataField="Value" HeaderText="Transaction Value" DataFormatString="{0:N2}" />
        <asp:BoundField DataField="Fee" HeaderText="Fee" DataFormatString="{0:N2}" />
        <asp:BoundField DataField="InsertedBy" HeaderText="Purchased By" />
        <asp:ButtonField ButtonType="Button" CommandName="cmdDetail1" HeaderText="View Details" Text="View" ControlStyle-CssClass="openModal"/>
        <asp:TemplateField ShowHeader="False">
            <ItemTemplate>
                <div>
                    <asp:Button ID="btnOpen" runat="server" Text="Show Gridview" CssClass="openModal" CommandName="cmdDetail2"/>
                        <div class="modal" id="idModal">
                            <div class="container">
                                <div class="modal-header">
                                    <h1>Transaction Details<a class="close-modal" href="#">&times;</a></h1>
                                </div>
                                <div class="modal-body">
                                    <asp:GridView ID="gvDetail" runat="server" DataSourceID="SqlgvDetail" AutoGenerateColumns="false"
                                    OnRowDataBound="gvDetail_RowDataBound" CssClass="table table-hover table-bordered" EmptyDataText="No data to display." >
                                        <Columns>
                                            <asp:BoundField DataField="metalid" HeaderText="Metal ID"/>
                                            <asp:BoundField DataField="enddate" HeaderText="End Date" DataFormatString="{0:dd-MM-yyyy}" />
                                            <asp:BoundField DataField="startdate" HeaderText="Start Date" DataFormatString="{0:dd-MM-yyyy}" />
                                            <asp:BoundField DataField="clientref" HeaderText="Client Ref" />
                                            <asp:BoundField DataField="quantity" HeaderText="Quantity" DataFormatString="{0:N2}" />
                                        </Columns>
                                    </asp:GridView>
                                </div>
                                <div class="modal-footer">
                                    <asp:Button ID="btn_close" runat="server" Text="OK" CssClass="close-modal btn-sm btn-primary"/>
                                </div>
                            </div>
                        </div>
                    <div class="modal-backdrop"></div>
                </div>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
代码隐藏:

protected void gvSummary_RowCommand(object sender, GridViewCommandEventArgs e)
{
    int index = Convert.ToInt32(e.CommandArgument);
    string name = e.CommandName.ToString();
    string clientRef = gvSummary.Rows[index].Cells[0].Text;
    Response.Write("<br> index = " + index);
    Response.Write("<br> name = " + name);
    Response.Write("<br> clientRef = " + clientRef);

    SqlgvDetail.SelectCommand = " SELECT td.metalid , td.enddate , td.startdate , td.clientref , td.quantity " +
                                " FROM trxdetail td " +
                                " WHERE td.clientref = " + "'" + clientRef + "'";
}
单击时,SQL是正确的,Response.Write在gvSummary\u row命令中设置了正确的变量。但是,模式窗口不会打开

单击btnOpen时,模式窗口打开,但未在gvSummary\u row命令中设置变量

我似乎无法完成这项工作,因此非常感谢您的帮助。
谢谢。

根据您的标签,您正在尝试实现引导模式吗?如果是,则在任何按钮中都看不到属性。还要看到这一点-请记住,回发将删除模式调用-引导模式被激活客户端如果要弹出打开引导模式,则必须为每一行预填充内部gridview并将其隐藏在包含的div中,或者在open上进行ajax调用,返回数据,然后根据您试图实现引导模式的标记排列或使用这些数据填充某种形式的客户端网格系统?如果是,则在任何按钮中都看不到属性。还要看到这一点-请记住,回发将删除模式调用-引导模式被激活客户端如果要弹出打开引导模式,则必须为每一行预填充内部gridview并将其隐藏在包含的div中,或者在open上进行ajax调用,该调用返回数据,然后您可以安排或使用这些数据填充某种形式的客户端网格系统