[英]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.