C# 如何在嵌套的中继器中保留记录的跟踪?
我有以下实施: 正如您所见,我有一个转发器(列出了机器)和一个嵌套转发器(列出了每台机器内的WindowsServices)。对于每个Windows服务,我都可以使用按钮执行操作。但是,要执行此操作,我需要知道涉及哪台机器和哪种WindowsService 这是我的代码:C# 如何在嵌套的中继器中保留记录的跟踪?,c#,asp.net,itemdatabound,nested-repeater,itemcommand,C#,Asp.net,Itemdatabound,Nested Repeater,Itemcommand,我有以下实施: 正如您所见,我有一个转发器(列出了机器)和一个嵌套转发器(列出了每台机器内的WindowsServices)。对于每个Windows服务,我都可以使用按钮执行操作。但是,要执行此操作,我需要知道涉及哪台机器和哪种WindowsService 这是我的代码: protected void Page_Init(object sender, EventArgs e) { rptMachine.ItemDataBound += new Repe
protected void Page_Init(object sender, EventArgs e)
{
rptMachine.ItemDataBound += new RepeaterItemEventHandler(rptMachine_ItemDataBound);
}
protected void Page_Load(object sender, EventArgs e)
{
// bind the Machine repeater
rptMachine.DataSource = _monitoringService.Machines;
rptMachine.DataBind();
}
protected void rptMachine_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater nestedRepeater = (Repeater) e.Item.FindControl("rptWindowsService");
nestedRepeater.DataSource = ((IMachine) e.Item.DataItem).WindowsServices;
nestedRepeater.DataBind();
Button btnActionInner = null;
// bind the action button situated inside the nested repeater
foreach(RepeaterItem ri in nestedRepeater.Items)
{
if((Button)ri.FindControl("btnAction") != null)
{
btnActionInner = (Button) ri.FindControl("btnAction");
btnActionInner.CommandName = "ActionState";
btnActionInner.CommandArgument = strWindowsService;
}
}
}
}
protected void rptWindowsService_ItemCommand(object source, RepeaterCommandEventArgs e)
{
// do the specific action stop/run for the windows service
if (e.CommandName == "ActionState")
{
if(((Button)(e.CommandSource)).Text.Equals("Stop"))
{
}
else if(((Button)(e.CommandSource)).Text.Equals("Run"))
{
}
}
}
}
}
因此,基本上我需要知道(在rptWindowsService_ItemCommand
中)操作所涉及的对是什么
最好的方法是什么
不要犹豫,要求更多的澄清
谢谢关于DataboundItem在代码中为“当前”计算机/窗口服务设置一个临时属性,然后绑定到它们
<asp:Repeater DataSource="<%# MachineList %>" OnItemDataBound="Machine_DataBound">
<asp:Repeater DataSource="<%# ((Machine)Container.DataItem).Services %>">
<asp:Button id="whatever" Text='<%# string.Format("Kill Service ({0}.{1})", CurrentMachine.Name, ((Service)Container.DataItem).Name); %>' />
</asp:Repeater>
</asp:Repeater>
private Machine CurrentMachine { get; set; }
public void Machine_DataBound(object sender, RepeaterItemEventArgs e)
{
CurrentMachine = e.Item as Machine;
}