单击 ImageButton 后动态表数据消失
我有一个表单,它搜索单个表(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的错误是由于您必须在每次加载时向页面添加动态创建的控件。 如果您在 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