获取GridView控件在用户控件的多个从codebehind [英] Get GridView in Multiple UserControl from codebehind
本文介绍了获取GridView控件在用户控件的多个从codebehind的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
IpInterfaceUC用户控件:
<div id="dvChannel" runat="server" style="height: 205px; width: 550px; overflow: auto;
margin-left: 5px;">
<asp:GridView ID="gvChannelUC">
</div>
codeBehind用于初始化
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
}
HTML展
<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>
问
我如何从多个用户控件得到gridview的?
Question How do I get gridview from multiple UserControl?
推荐答案
通过您的用户控件的公共属性暴露GridView的:
Expose the gridview through a public property on your UserControl:
public GridView Grid
{
get { return gvChannelUC; }
}
然后
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
...
这篇关于获取GridView控件在用户控件的多个从codebehind的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文