我的ASP.NET页面上有以下标记片段
<asp:GridView ID="gvParent" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="hfAppID" runat="server" />
<asp:GridView id="gvChild" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvChild_RowDataBound" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我需要在hfAppID
事件中访问分配给gvChild_RowDataBound
隐藏字段控件的值
protected void gvChild_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
//need to access the hfAppId hidden field control from parent here
}
}
我将如何完成此任务?
答案 0 :(得分:3)
您可以使用 Parent.FindControl 。
protected void gvChild_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var gvChild = sender as GridView;
var hfAppID = gvChild.Parent.FindControl("hfAppID") as HiddenField;
var id = hfAppID.Value;
}
}