首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在嵌套的中继器中保留记录的踪迹?

如何在嵌套的中继器中保留记录的踪迹?
EN

Stack Overflow用户
提问于 2010-06-18 23:30:47
回答 1查看 316关注 0票数 0

我有以下实现:

如您所见,我有一个中继器(列出了机器)和一个嵌套的中继器(列出了每台机器内的WindowsServices )。对于每个Windows服务,我都可以使用按钮执行操作。但是,要执行此操作,我需要知道哪个机器和哪个WindowsService是相关的。

这是我的代码:

代码语言:javascript
复制
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内部)操作所关注的对是什么。

那么最好的方法是什么呢?

请不要犹豫,要求更多的澄清!

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-06-18 23:40:17

在DataboundItem上,在代码隐藏中设置一个临时属性为“当前”计算机/窗口服务,然后绑定到它们。

代码语言:javascript
复制
<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>

代码隐藏:

代码语言:javascript
复制
 private Machine CurrentMachine { get; set; }

 public void Machine_DataBound(object sender, RepeaterItemEventArgs e)
 {
     CurrentMachine = e.Item as Machine;
 }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3070972

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档