简体   繁体   English

如何在ASP.Net中为动态gridviews设置页面加载?

[英]How to set up page loading in ASP.Net for dynamic gridviews?

Here is how my code is set up. 这是我的代码设置方式。 The webpage itself works like this: 该网页本身的工作方式如下:

You have a drop down that allows you to select between different values. 您有一个下拉菜单,允许您在不同的值之间进行选择。 Lets call it dropdown A. Depending on the value selected, a gridview gets generated. 让我们将其称为下拉列表A。根据选择的值,将生成一个gridview。

How generation works: When a item in the dropdown A gets selected, inside the selectedIndexChanged is a method call to a function that creates a DataTable. 生成的工作方式:在下拉列表A中的一项被选中时,selectedIndexChanged内部是对创建DataTable的函数的方法调用。 That datatable gets binded to the gridview inside selectIndexChanged. 该数据表被绑定到selectIndexChanged内部的gridview。

When it gets bounded, onRowBoundEvent gets called, and this is where I add all the necessary controls with unique IDs. 当它受到限制时,将调用onRowBoundEvent,这是我在其中添加所有具有唯一ID的必要控件的地方。

There is a button called saved that looks at the data in gridview, and saves it. 有一个名为“保存”的按钮,它可以查看并保存gridview中的数据。

Problem: When I press save, there are no controls in the gridview for me to find. 问题:当我按保存时,gridview中没有可供我查找的控件。

I can use findControl since I know all the ids, but how do I make the controls stick around? 因为我知道所有ID,所以可以使用findControl,但是如何使控件保持不变?

If I bind it in the page_load, how do I know what gridview to generate since if I select a value from dropdown A, page_load still fires before I can get a selection value from dropdown A, so I can't make a simple conditional statement based on the dropdown value. 如果我将其绑定到page_load中,如何知道要生成的gridview,因为如果我从下拉列表A中选择一个值,则page_load仍会触发,然后才能从下拉列表A中获得选择值,因此我无法做出简单的条件语句根据下拉值。

I can't show any code, sorry. 抱歉,我无法显示任何代码。 But this is more of a conceptual question I have. 但这更多是我的概念性问题。

I was able to figure this out on my own. 我能够自己解决这个问题。

PrePage_Load during the project lifecycle has access to controls. 在项目生命周期中,PrePage_Load可以访问控件。 Dropdown A in my example can be accessed in PrePage_Load, allowing me to get the necessary values and set them before Page_Load starts. 在我的示例中,下拉列表A可以在PrePage_Load中访问,这使我可以获得必要的值并在Page_Load启动之前进行设置。

For controls in the gridview, I made it so the gridview does not automatically load from viewstate, and I rebuilt the gridview myself during page_load. 对于gridview中的控件,我做到了,因此gridview不会自动从viewstate加载,因此我在page_load期间自行重建了gridview。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM