Using ObjectDataSource and passing Object as a parameter
Posted on 2/22/2008 4:58:57 AM
in #ASP.NET 2.X
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
|
Posted on 5/20/2008 9:26:56 PM
Hi Vikram,
Can u please tell me how to do "deleting data in xml table using class and objectdatasource". I can able to retrieve,insert and update data but cant delete...I wrote the code as follows in class file for deleting:
public void deleting(Int32 rno)
{
int j = give_index(rno);
if (j != -1)
{
ds.Tables[0].Rows[j].Delete();
ds.WriteXml(xml_path);
}
}
In the above code, it is taking "rno" as 0 for every row( it is suppose to take the "rno" cell's value but it is not taking, for updating it is taking the correct value)..
Any help please..
|