我有一个GridView(gvSummary),每行包含一个按钮。单击此按钮时,将打开一个显示第二个GridView(gvDetail)的模式窗口。从源代码中,我似乎无法引用第二个GridView。当我尝试它时会给出错误消息"The name gvDetail does not exist in the current context."
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<div>
<asp:Button ID="btn_open" runat="server" OnClick="btn_open_Click" Text="Show Gridview" CssClass="openModal" CommandName="cmdDetail"/>
<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>
上面的TemplateField位于第一个Gridview中。 有没有办法从源代码中引用这个GridView?
感谢任何帮助。
答案 0 :(得分:1)
如果我理解正确,您正在尝试获取子gridview gvDetail
的参考?如果是这样,我认为你可以做到这一点。您应该可以通过其父网格视图gvDetail
事件找到OnROwDataBound
。
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// get the reference of child gridview
GridView gvDetail = e.Row.FindControl("gvDetail") as GridView;
}
}