Bulk edit only certain rows?

Topics: Developer Forum
Jul 27, 2007 at 12:08 PM
Edited Jul 27, 2007 at 12:09 PM
Hi there,

I've trying to customize the BulkEditGridView so that bulk editing can be enabled for only certain rows, based on some field values.

In Matt's blog entry he hints that this should easily be possible, but I am having difficulty implementing this.

The main problem here is that the RowState is set to Edit or Normal in the CreateRow function. Unfortunately at this time only the RowIndex is available. I cannot find any way of getting to the field values that will be bound to the row.

On the other hand, in the OnRowDataBound Event I have the field values, but the Row is already initialized, so I presume I cannot do this again. I have not tested this yet, but I presume it would give an exception or else create a loop.

So the only alternative that I see is using the RowIndex property. But I cannot find a way to retrieve a row of data from the DataSource of the GridView.

I am missing something here, or is calling the query a second time the only option?

Kind regards,
Ries
Jul 27, 2007 at 2:29 PM
I think I found it:

In CreateChildControls you have access to the DataSource. Store a reference in a private variable and use it in the CreateRow function to inspect row/field values and set RowState to Edit/Normal accordingly.

Now the difficult part: When the page postbacks you have to set the RowState exactly as before or you will get a ViewState error because it doesn't match the Control tree. Only at this time you cannot use the original datasource because that is no longer available. You have to make do with what is in the ViewState.

Therefor on the initial run you have to store the rowIndexes of the rows you set to Edit in a ViewState variable. Now after the PostBack you can retrieve the indexes from the ViewState and if there is a match then you set the RowState to Edit.

That's about it roughly. Ofcourse you have to reset the RowIndexes ViewState variable when a new query is executed.

An easier solution is appreciated ;-)