如何在嵌套转发器中保留记录的踪迹?

发布于 2024-09-06 04:19:16 字数 2370 浏览 3 评论 0 原文

我有以下实现:

正如您所看到的,我有一个转发器(列出机器)和一个嵌套转发器(列出每台机器内的 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内部)操作所涉及的对是什么。

最好的方法是什么?

请随时要求更多说明!

谢谢

I have the following implementation:

alt text

As you can see I have a repeater (listing the Machines) and a nested repeater (listing the WindowsServices inside each Machine). For each Windows Service I can perform an action using a button. However, to perform this action I need to know which Machine and which WindowsService are concerned.

This is my code:

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"))
                {

                }
            }
        }

    }
}

So basically I need to know (inside rptWindowsService_ItemCommand) what is the pair that is concerned by the operation.

What's the best way to do that?

Don't hesitate to ask for more clarifications!

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彡翼 2024-09-13 04:19:16

在 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;
 }

On DataboundItem set a temporary property in your code-behind to the "current" Machine / Window Service, then just bind to them.

<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>

Code Behind:

 private Machine CurrentMachine { get; set; }

 public void Machine_DataBound(object sender, RepeaterItemEventArgs e)
 {
     CurrentMachine = e.Item as Machine;
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文