如何在RowCommand中定义网格视图

时间:2015-10-01 04:25:47

标签: c# asp.net gridview

我有以下网格视图gvAgreement和嵌套网格视图gvProducts

我希望在gvProducts

中定义gvAgreement_RowCommand

我在gvProducts

中定义了gvAgreement_OnRowDataBound

通过以下代码

protected void gvAgreement_OnRowDataBound(object sender, GridViewRowEventArgs e)
{ 
    GridView gvProducts = e.Row.FindControl("gvProducts") as GridView;
}

protected void gvAgreement_RowCommand(object sender, GridViewCommandEventArgs e)
{
    //your suggest code
}

1 个答案:

答案 0 :(得分:1)

这将让您在父网格视图中找到任何子控件。

GridViewRow gvRow = (GridViewRow)((Control)e.CommandSource).NamingContainer;
Int32 rowIndex = gvRow.RowIndex; // required if you want to find index of the control from where event has been raised.  
GridView gvProducts = gvRow.FindControl("gvProducts") as GridView;