所以我有一个 GridView ( gvSummary
),其中包含一个模板字段,里面有一个按钮 ( btnOpen
)。此按钮的目的是gvDetail
在模式窗口中打开第二个 GridView(),基于来自gvSummary
.
我遇到的问题是我似乎无法gvSummary_RowCommand
通过单击按钮来执行代码btnOpen
。我可以从中执行代码,<asp:ButtonField>
但这不会打开第二个 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="#">×</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 + "'";
}
当我单击 时<asp:ButtonField>
,SQL 是正确的,并且 Response.Write() 在 中设置了正确的变量gvSummary_RowCommand
。但是,模式窗口不会打开。
当我单击btnOpen
时,模式窗口打开,但没有在 中设置变量gvSummary_RowCommand
。
我似乎无法进行这项工作,因此不胜感激。谢谢。