سؤال

لدي التنفيذ التالي:

alt text

كما ترون ، لدي مكرر (سرد الآلات) ومكتب متداخل (يسرد الخدمات داخل كل جهاز). لكل خدمة 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