链接按钮动态单击

时间:2011-10-24 11:49:14

标签: asp.net webforms linkbutton

我的项目有问题。我正在动态创建链接按钮以显示项目。当我点击一个项目它正在激活,我可以动态显示错误的链接按钮。现在,当我点击一个错误时,我想动态地显示描述,但是这个点击事件没有触发,我无法解决它..这是我的代码。

private void LoadXmlBugs(XDocument xDocument)
    {
        //Load all bugs
        IEnumerable<Bugs> data = from query in xDocument.Descendants("bugs")
                                 where (((string)query.Element("bug_status") == "NEW") ||
                                 ((string)query.Element("bug_status") == "REOPENED") ||
                                 ((string)query.Element("bug_status") == "New"))
                                 select new Bugs
                                 {
                                     Bug_Id = (string)query.Element("bug_id"),
                                     Short_Desc = (string)query.Element("short_desc"),
                                     Bug_Status = (string)query.Element("bug_status"),
                                     Priority = (string)query.Element("priority"),
                                     Creation_Ts = (string)query.Element("creation_ts"),
                                 };

        Bugs = new List<Bugs>(data);
        string statut = Request.QueryString.Get("bug_status");

        foreach (Bugs b in Bugs)
        {

            System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
            img.ImageUrl = ("~/Img/FolderIco.png");
            PanelAllBugs.Controls.Add(img);
            LinkButton lkButtonBugs = new LinkButton();
            lkButtonBugs.Click += new EventHandler(lkButtonBugs_Click);
            lkButtonBugs.ID = b.Bug_Id;
            lkButtonBugs.Tag = b.Short_Desc;
            lkButtonBugs.Text = b.Bug_Status + "     " + b.Short_Desc + "      " + "<br>";
            lkButtonBugs.Attributes.Add("runat", "server");
            PanelAllBugs.Controls.Add(lkButtonBugs);

        }
    }


void lkButtonBugs_Click(object sender, EventArgs e)
    {
        bugId = ((sender as LinkButton).ID);

        LoadTheDescriptionForABug(bugId, ((sender as LinkButton).ID));
        LoadBugsComments();
        LoadBugsAttachments();
    }

有人可以帮助我吗?

非常感谢你。

1 个答案:

答案 0 :(得分:2)

您从哪里调用该方法:LoadXmlBugs

应该在每个PostBack添加动态添加的控件,所以一切都取决于你在何处/何时调用上面的方法。

尝试从Page_Init事件处理程序中调用LoadXmlBugs