Get GridView in Multiple UserControl from codebehind

后端 未结 2 1817
遥遥无期
遥遥无期 2021-01-26 18:31

IpInterfaceUC UserControl:

2条回答
  •  时光说笑
    2021-01-26 19:19

    While you can recursively use FindControl to find it, a much better approach is to let the UserControl IpInterfaceUC decide how to bind data to the controls within it.

    You could add a public method ShowData to you UserControl and pass the data to be displayed to it. It can then assign it to gvChannelUC.

    int indexInterface=0;
    foreach (DataRow row in dtDevicesListByRole.Rows)
    {
        var ctrIpInterfaceUC = (Test2.SetupGroup.Ipservice.IpInterfaceUC)LoadControl("IpInterfaceUC.ascx");
        ctrIpInterfaceUC.ShowData(myRows);
        ctrIpInterfaceUC.ID = "device_"+ip+"_"+port+"$"+indexInterface;
        phDevices.Controls.Add(ctrIpInterfaceUC);//PlaceHolder for add many UserControl
    }
    

提交回复
热议问题