我有以下实现:
如您所见,我有一个中继器(列出机器)和一个嵌套中继器(列出每台机器内的 WindowsServices)。对于每个 Windows 服务,我可以使用按钮执行操作。但是,要执行此操作,我需要知道涉及哪个 Machine 和哪个 WindowsService。
这是我的代码:
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
)操作所关注的对是什么。
最好的方法是什么?
不要犹豫,要求更多澄清!
谢谢