Hi,
I have a Page with a WebGrid and an ObjectDataSource. The WebGrid has AutoGenerateColumns set to false. I have defined 2 columns which are both bound (IsBound=true). When the page is shown, the select method of the ObjectDataSource is triggered. It returns a DataView with 4 rows.
1. When I set a breakpoint on the InitializeLayout event handler, the e.Layout.Bands[0].Columns.Count is zero. Is this because I didn't autogenerate the columns? I would expect a value of 2.2. The WebGrid is not bound to the 4 rows in the Dataview. But when I force a postback by a simple button click the WebGrid gets bound and now in the InitializeLayout event handler the e.Layout.Bands[0].Columns.Count is 2. Why didn't it bind on the first page load?
thanks,Jeroen
Hi Jeroen,
I was having the same problem as you until I changed the value of IsBound to false.
Hope this helps
Aidan
Hi Aidan,
I tried your suggestion and it worked. But now I do not understand wat the IsBound property is used for... A side effect of setting the IsBound property to false, is that the Update method of the ObjectDataSource does not contain the changed values of my WebGrid. This is not really what I want. I want the data to be bound to the WebGrid on the first load and the Update method to contain the changed values of the data. Is this even possible?
IsBound is basically just used by the grid so it knows which columns were generated from the data source and which ones were added by the user in a design time grid. If AutoGenerateColumns is set to false, IsBound should also be set to false on the columns to tell the grid not to touch them. Set BaseColumnName to tell the grid which column from your DataSource to load the data from.
The other thing to double check is that the DataKeyField property of the grid has been set. The grid doesn't get enough information from the ObjectDataSource to know which of the fields is the data key and it won't be able to do updates properly because the order of the cells is likely to change in grids with filtering and sorting turned on.
If this doesn't help, I'd suggest submitting a developer support issue. DataBinding issues can be quite complex and hard to diagnoze. The developer support team will be able to take a look at what you're doing and help you figure out what's going wrong.
I found the problem. I set the DataObjectTypeName of my ObjectDataSource to a valid classname to use in the Update and Delete methods. As a result the Select method of the ObjectDataSource must return a list of objects of this specific type. I was returning a DataView. After changing the code to return a valid list and setting the IsBound property to true in design time, my initial plan worked.
It is still strange (bug?) that even when I used a DataView as the return value, the select method still worked after forcing a postback!