简体   繁体   English

防止在加载页面上填充AspxGridView

[英]Prevent AspxGridView from populating on loading page

I have AspxGridView on my page. 我的页面上有AspxGridView。 I want users to be able to set up some data on the web form, and after they press one button, the data from screen is being read, validated and bussines object is being created. 我希望用户能够在Web表单上设置一些数据,然后按一个按钮,然后读取,验证屏幕中的数据并创建bussines对象。 This object has a GetData() function, and returns an array of objects representing rows in a grid. 该对象具有GetData()函数,并返回表示网格中行的对象数组。
I want ASPXGrid not to populate, until user clicks the button. 我希望在用户单击按钮之前不填充ASPXGrid。 I know I can set DataSourceId in design time to null – but then I lost availability of synchronizing grid columns with object properties (I cannot add or edit some column properties for new columns). 我知道我可以在设计时将DataSourceId设置为null –但是我失去了将网格列与对象属性同步的可用性(我无法为新列添加或编辑某些列属性)。 I know I can intercept ObjectCreating event and provide grid with an fake object returning empty data sets. 我知道我可以拦截ObjectCreating事件,并为网格提供一个返回空数据集的伪造对象。 But are there any more elegant solutions? 但是,还有其他更优雅的解决方案吗?

When are you doing the DataBind() call? 您什么时候进行DataBind()调用? Couldn't you just place that inside an if block to make sure it only happens on postback? 您不能只是将其放置在if块中以确保它仅在回发时发生吗?

if(Page.IsPostBack) {
    DoDataBindingStuff();
}

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

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