views:

945

answers:

1

I have AspxGridView on my page. 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. This object has a GetData() function, and returns an array of objects representing rows in a grid.
I want ASPXGrid not to populate, until user clicks the button. 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). I know I can intercept ObjectCreating event and provide grid with an fake object returning empty data sets. But are there any more elegant solutions?

+1  A: 

When are you doing the DataBind() call? Couldn't you just place that inside an if block to make sure it only happens on postback?

if(Page.IsPostBack) {
    DoDataBindingStuff();
}
Tomas Lycken
If I set DataSourceId data binding is made automaticaly behind my back. Now I do not set DataSourceId on design time, instead I do it on runtine when user clicks my button.
smok1
You could try to cancel the OnDataBinding event of your data source if the page is not a postback. I'm not sure that your column headers would show up, though...
Tomas Lycken