質問

次の実装があります。

alt text

ご覧のとおり、リピーター(マシンのリスト)とネストされたリピーター(各マシン内のWindowsServicesをリスト)があります。各Windowsサービスについて、ボタンを使用してアクションを実行できます。ただし、このアクションを実行するには、どのマシンとどの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)操作に関係するペアは何ですか。

それを行うための最良の方法は何ですか?

もっと明確にすることを尋ねることを躊躇しないでください!

ありがとう

役に立ちましたか?

解決

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;
 }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top