IpInterfaceUC 用户控制:
<div id="dvChannel" runat="server" style="height: 205px; width: 550px; overflow: auto;
margin-left: 5px;">
<asp:GridView ID="gvChannelUC">
</div>
Init 的代码隐藏
int indexInterface=0;
foreach (DataRow row in dtDevicesListByRole.Rows)
{
ctrIpInterfaceUC = (Test2.SetupGroup.Ipservice.IpInterfaceUC)LoadControl("IpInterfaceUC.ascx");
Control ctr = (Control)ctrIpInterfaceUC;
ctr.ID = "device_"+ip+"_"+port+"$"+indexInterface;
phDevices.Controls.Add(ctr);//PlaceHolder for add many UserControl
}
网页显示
<div id="dvChannel">
<div id="device_192.168.2.19_3331_0_pnlChannelUC">
<div id="device_192.168.2.19_3331_0_dvChannel">
<table id="device_192.168.2.19_3331_0_gvChannelUC">
</table>
</div>
</div>
<div id="dvChannel">
<div id="device_192.168.2.19_3331_1_pnlChannelUC">
<div id="device_192.168.2.19_3331_1_dvChannel">
<table id="device_192.168.2.19_3331_1_gvChannelUC">
</table>
</div>
</div>
Question如何从多个 UserControl 获取 gridview?
通过 UserControl 上的公共属性公开 gridview:
public GridView Grid
{
get { return gvChannelUC; }
}
Then
List<string, string> Grids = new List<string, string>(); // <UCId, GridId>
...
ctrIpInterfaceUC = (Test2.SetupGroup.Ipservice.IpInterfaceUC)LoadControl("IpInterfaceUC.ascx");
string Id = "device_"+ip+"_"+port+"$"+indexInterface;
GridView ctrGridView = ctrIpInterfaceUC.Grid;
Grids.Add(Id, ctrGridView.ClientID);
Control ctr = (Control)ctrIpInterfaceUC;
ctr.ID = Id
phDevices.Controls.Add(ctr);//PlaceHolder for add many UserControl
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)