Passing Object as a parameter in ObjectDataSource

Hi,

 

ObjectDataSource was a great addition to Asp.Net 2.0. But when working with asp.net 2.0’s ObjectDataSource had one limitation when working in Visual Studio designer. When working with ObjectDataSource we cannot pass object as a parameter. We always need to pass string, integer etc as the parameter.

 

But many a times we want to pass some object as parameter instead of passing all the values as string. Passing all the values can also be difficult when working with large number of columns.

 

To pass an object as the parameter, you need to use the event of the ObjectDataSource. To pass parameters in the select query use the selecting event in the ObjectDataSource. Below is an example on how to pass the object in the ObjectDataSource

OBJParam ObjParam = new OBJParam();
ObjParam.Value = "no";
ObjParam.SomeValue = "Yes";           
e.InputParameters["ObjParam"] = ObjParam;    

 

This way we can pass an Object in the ObjectDataSource as a parameter. If you need to pass object during insert use Inserting event. Similarly use Updating and Deleting event in the ObjectDataSource.

 

Vikram

No Comments