Victor

Victor

  • NA
  • 7
  • 0

Delegate assignable as a class property to be called within a class

Jan 18 2010 9:42 PM




I'm wondering if it is possible to allow a developer to write a function in aspx codebehind, place the name of the function in a custom WebControl's property, and have that function be called within said WebControl.
 

The problem I'm trying to solve is this:  I have a custom GridView that allows the user to page, sort, search and make changes to data from a database table without committing the changes to the data to the table until the user clicks a "Save" button.  I bind my custom gridview to a databaseobject.  That databaseobject accesses select and update methods that are defined by my custom business logic objects, which in turn access datasets I created using the dataset wizards.
 

I solved the issue of caching the changes by adding an object to record the changes and saving/loading that object to/from viewstate.
 

The issue I'm running into is matching the changed values to the rows that the changed values apply to.  I can't use RowIndex because the RowIndex indexes the currently visible rows, and as the user pages the gridview the rowindex will change which row/dataitem it actually points to.  Originally I used DataItemIndex, but if the user changes the search parameters and thus changes the underlying dataset, the datasex index is reset and so the old dataitemindex does not apply any more.
 

So what I am trying now is matching based off the DataKeys.  I can access the DataKeys within my custom gridview, and I'm trying to search through my custom object that stores the changes to find a matching set of keys, but the problem I'm running into now is that a DataKey stores the value as type "object" and I can't get a match by comparing two values as objects.  I need to cast the objects first before comparing, but inside my custom gridview I have no idea what type those objects, the value of each datakey, will be.  They could be ints, strings, etc.
 

So I figured I would allow the user to define that process of comparison outside my custom gridview in the aspx codebehind itself and then tell the gridview to call that function when its time to match the DataKeys of the row to the datakeys of my custom "changes" object.
 

Is this possible?
 

Any suggestions of a better way to go about doing this?

Answers (3)