私は次の実装を持っています:
ご覧のとおり、リピーター (マシンのリスト) とネストされたリピーター (各マシン内の WindowsService のリスト) があります。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
したがって、基本的には、操作に関係するペアを(内部で) 知る必要があります。
それを行う最善の方法は何ですか?
さらに詳しい説明を求めることを躊躇しないでください!
ありがとう