0

我正在从下面的按钮 (btnOpen) 打开一个模式窗口。此 bhutton 位于 GridView 内。它需要在模式窗口中打开另一个 Gridview,但我的代码不起作用:

<asp:TemplateField>
    <ItemTemplate>
        <asp:Button ID="btnOpen" runat="server" Text="Show Gridview" CommandName="cmdDetail" CommandArgument="<%# ((GridViewRow) Container).DataItemIndex %>"/>
    </ItemTemplate>
</asp:TemplateField>

我的模态窗口:

<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" AutoGenerateColumns="false"  DataSourceID="SqlgvDetail"
            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>

Sql 数据源:

<asp:SqlDataSource ID="SqlgvDetail" runat="server" ConnectionString="<%$ ConnectionStrings:InventoryConnectionString %>">
</asp:SqlDataSource>

代码背后:

protected void gvSummary_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "cmdDetail")
    {
        // Retrieve the row index stored in the CommandArgument property.
        int index = Convert.ToInt32(e.CommandArgument);
        // Retrieve the row that contains the button from the Rows collection.
        GridViewRow row = gvSummary.Rows[index];

        Button btnOpen = row.FindControl("btnOpen") as Button;
        btnOpen.CssClass = "openModal";

        string clientRef = row.Cells[0].Text;

        SqlgvDetail.SelectCommand = " SELECT td.metalid , td.enddate , td.startdate , td.clientref , td.quantity FROM trxdetail td " +
                                    " WHERE td.clientref = '" + clientRef + "'";
        gvDetail.DataBind();
    }
}

当我单击一个按钮时,它会正确获取 SQL 命令,但不会加载模式。如果我然后再次单击该按钮,它会在第一次单击时显示带有 SQL 命令的模态。

我已经坚持了好几天了,所以感谢您的帮助。

4

0 回答 0