简体   繁体   English

当我从数据库中删除相应的行时,如何获取用于更新数据库行的动态控件以消失

[英]how do i get my dynamic controls for updating database rows to go away when i delete the corresponding row from the DB

Ok so basically my situation is this: i have a button to search a database. 好的,所以基本上我的情况是这样的:我有一个搜索数据库的按钮。 when you click the button I call a function (createRows()) that gets the data from the DB and for each row creates a user control that i made and populates its data with the data from the DB. 当您单击按钮时,我调用了一个函数(createRows()),该函数从DB中获取数据,并为每一行创建一个用户控件,该控件由我创建并用DB中的数据填充。 i also call createRows() in the Page_Load function so that the controls will persist. 我还可以在Page_Load函数中调用createRows(),以便控件将持久存在。

inside my usercontrol there is a delete button which in the user control's code behind C# file deletes that row of the DB. 在我的用户控件内有一个删除按钮,该按钮在C#文件后面的用户控件代码中删除数据库的该行。 this all works fine but i have to hit the search button again for the user control to go away and im wondering why it wont actually go away on its own since i am calling createRows() in the Page_Load anyways? 这一切都很好,但是我必须再次按下搜索按钮才能使用户控件消失,我想知道为什么它实际上不会自行消失,因为无论如何我还是要在Page_Load中调用createRows()?

My guess would be viewstate is caching the results. 我的猜测是viewstate正在缓存结果。 Set EnableViewState="false" on the control with the rows. 在具有行的控件上设置EnableViewState =“ false”。

ok i think i might have figured it out i found this tutorial: 好的,我想我可能已经知道了,我找到了本教程:

http://www.codeproject.com/KB/user-controls/Page_UserControl.aspx http://www.codeproject.com/KB/user-controls/Page_UserControl.aspx

and then i did the usercontrol to page communication and called createRows() from the usercontrol in addition to having it called in Page_Load. 然后我做了用户控件来进行页面通信,除了在Page_Load中调用它之外,还从用户控件中调用了createRows()。 seems to be working, any other comments or suggestions are welcome though 似乎可行,但是欢迎其他任何意见或建议

thanks, 谢谢,

Leo 狮子座

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我有 3 行的 SQLite 数据库,当我从行中删除数据时,数据会丢失但行仍然会,我该如何删除那个空白行? - I have SQLite db with 3 rows, when i delete data from row, data will lost but row will still, how can i delete that blank row? 如何使用此方法删除数据库中的行? - How do I delete a row in my database using this method? 如何使这些错误消失? - How do I make these errors go away? DbContext - 如何在更新数据库时阻止数据库创建新记录? - DbContext - how do I stop my database from creating new records when I'm updating them? 如何从数据库中删除整行 - How do I delete an entire row from a database 使用 EntityFrameworkCore 搭建脚手架后,如何从数据库中获取行数 - How do i get the row Count from my Database after i've scaffolded it with EntityFrameworkCore go 如何在插入不同 ID 对应于相同名称的记录列表后修复我的数据库表 - How do I go about fixing my database table after inserting a list of records different id's corresponding to same name 从.NetCore2.1更改TargetFramework时如何替换Database.ExecuteSqlQuery - How do I replace Database.ExecuteSqlQuery when changing TargetFramework away from.NetCore2.1 如何从 datagridview 控件中的数据库中获取所选行的 id? - How do I get the id of the selected row from my database in a datagridview control? 如何删除部分键的数据库行? - How do I delete DB rows for a range of partial keys?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM