我有两个gridview Gv1,它是父级和gv2,它嵌套在Gv1中 我想找到子gridview的控件以及放置在两个网格之外的下拉列表的selectedindexchange中childgridview的itemtemplate内的标签
我在下拉列表选择的索引更改
中使用了此代码 GridView grid_child = grv_parent.FindControl("grv") as GridView;
if (grid_child != null)
{
Label lbl_asset_type = (Label)grid_child.FindControl("lbl_asset_type");
答案 0 :(得分:1)
我认为你想要一个ID为“lbl_asset_type”的标签,它位于父网格内的子网格内。可能存在语法错误,但尝试这样的事情(我没有测试过代码,但这应该给你一个大概的想法):
GridView grid_child = grv_parent.FindControl("grv") as GridView;
if (grid_child != null)
{
foreach (GridViewRow row in grid_child.Rows)
{
Label lblAssetType = (Label)grid_child.FindControl("lbl_asset_type");
//Use label here. Make sure to do a null check first
}
}