单击 ImageButton 后动态表数据消失

发布于 2024-07-08 00:17:23 字数 830 浏览 11 评论 0原文

我有一个表单,它搜索单个表(TServices)中发生在日期范围之间的所有行,然后填充表单下方的动态表。

现在,我在表中每个列表旁边添加一个删除 ImageButton。 这是我将 ImageButtons 添加到表格单元格的 C# 代码隐藏:

        ImageButton btnRemoveService = new ImageButton();
        btnRemoveService.EnableViewState = true;
        btnRemoveService.ImageUrl = "/images/icons/trash.gif";
        btnRemoveService.Click += new ImageClickEventHandler(btnRemoveService_Click);
        btnRemoveService.ID = "btnRemoveService-" + row["BillingID"].ToString();
        btnRemoveService.CommandArgument = row["BillingID"].ToString();
        tblCell.Controls.Add(btnRemoveService);

即使我在 btnRemoveService_Click() 中没有放置任何内容,动态表中的所有数据也会消失。 当我输入代码来实际删除存储过程时,数据从动态表中消失,并且数据库中没有任何更改。

编辑: 我将填充代码移至其自己的函数中,并在 btnRemoveService_Click() 末尾调用它。 这不应该重新加载数据吗?

I have a form that searches all rows in a single table (TServices) that occurred between the date range and then populates a dynamic table below the form.

Now I'm adding a delete ImageButton next to each listing in the table. Here's my C# code-behind for adding the ImageButtons to the table cell:

        ImageButton btnRemoveService = new ImageButton();
        btnRemoveService.EnableViewState = true;
        btnRemoveService.ImageUrl = "/images/icons/trash.gif";
        btnRemoveService.Click += new ImageClickEventHandler(btnRemoveService_Click);
        btnRemoveService.ID = "btnRemoveService-" + row["BillingID"].ToString();
        btnRemoveService.CommandArgument = row["BillingID"].ToString();
        tblCell.Controls.Add(btnRemoveService);

Even if I put nothing in btnRemoveService_Click(), all my data from the dynamic table disappears. When I put in the code to actually delete the stored procedure, the data disappears from the dynamic table and nothing is changed in the db.

Edit:
I moved the populate code into its own function and called it at the end of btnRemoveService_Click(). Shouldn't this reload the data?

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

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

发布评论

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

评论(1

黯然#的苍凉 2024-07-15 00:17:23

您的错误是由于您必须在每次加载时向页面添加动态创建的控件。 如果您在 page_init 方法中重新添加它们,它们将存在以便加载视图状态并成功触发单击事件。 这都与 ASP.NET 页面加载过程有关

Your error is due to the fact that you must add dynamically created controls to the page on EVERY load. If you re-add them inside the page_init method they will exist for viewstate to load and for the click events to fire successfully. It is all related to the ASP.NET Page Load process

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文