473,395 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ObjectDataSource programmatically instanciated

Hello,

I have some trouble to declare and instantiate dynamically an
ObjectDataSource in the codebehind file. The idea is to bind the
objectdatasource to a gridview and have automate sorting and paging.
The objectdatasource SelectMethod returns a dataview.

When my objectdatasource is declared in the codebehind, sorting is not
working and i receive following error when clicking on a datagrid's
column header. I made the same test declaring the ObjectDataSource in
the designer and sorting works perfectly... :

[HttpException (0x80004005): The GridView 'dgPackages' fired event
Sorting which wasn't handled.]
System.Web.UI.WebControls.GridView.OnSorting(GridV iewSortEventArgs
e) +323
System.Web.UI.WebControls.GridView.HandleSort(Stri ng sortExpression,
SortDirection sortDirection) +101
System.Web.UI.WebControls.GridView.HandleSort(Stri ng sortExpression)
+100
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
causesValidation, String validationGroup) +595
System.Web.UI.WebControls.GridView.RaisePostBackEv ent(String
eventArgument) +213

System.Web.UI.WebControls.GridView.System.Web.UI.I PostBackEventHandler.RaisePostBackEvent(String
eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+242
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+3840
Here is the declaration with the designer way :
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetPackagesByIdRestaurant"
SortParameterName="SortExpression" TypeName="DB">
<SelectParameters>
<asp:Parameter Name="IdRestaurant" Type="Int32" />
<asp:Parameter Name="SortExpression" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>

And here the codebind code version causing troubles :
ObjectDataSource ds = new ObjectDataSource();
ds.TypeName = "DB";
ds.SelectMethod = "GetPackagesByIdRestaurant";
ds.SelectParameters.Add(new Parameter("IdRestaurant",
System.TypeCode.Int32, restaurant.IdRestaurant.ToString()));
ds.SelectParameters.Add(new Parameter("SortExpression",
System.TypeCode.String, ""));
ds.SortParameterName = "SortExpression";
dgPackages.DataSource = ds;
dgPackages.DataBind();

Any help is welcome. Of course i could let the ObjectDataSource in the
designer but i prefer to do it within the code if possible...

Regards

Gilles Faessler

Jul 5 '06 #1
0 1856

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Don | last post by:
If I have an ObjectDataSource defined on a page can I use it programmatically to read data a load a dropdownlist? I need to do this so that I can add an item to the dropdown before the data from...
2
by: | last post by:
I've defined an ObjectDataSource against a dataset, and I can bind the ObjectDataSource's members to data controls. I'm wondering how to take the values in an ObjectDataSource and...
12
by: Jim Hammond | last post by:
I am passing the whole object instead or parameters in my select and update methods. I can get the updated object if I set UpdateMethod, let ASP.NET autogenerate an update button, and then press...
3
by: avezina | last post by:
We would like to use those new cool features of Asp.Net 2.0 like the ObjectDataSource in our project. I tried few basics examples and its work well. Let's say I have a page that displays a...
10
by: J055 | last post by:
Hi I've been trying out SqlCacheDependency using the ObjectDataSource and SQL Server 2005. It all works quite well with the minimum of configuration, e.g. <asp:ObjectDataSource...
2
by: Charlie | last post by:
Hi: I'm using the ObjectDataSource control to databind a Repeater. The method on business object that ObjectDataSource control point to takes as a parameter an instance of the...
2
by: Philip | last post by:
I can use a GridView and ObjectDataSource to bind my data using "Eval" expressions ... provided the GridView and related Column TemplateFields are defined as inline HTML. I prefer to...
2
by: JJ | last post by:
How can I set an ObjectDataSource's Parameter programmatically? The slight complication here is that I want to set this NOT in the 'Selecting' method of the ObjectDataSource, but elsewhere. I...
9
by: Kernel Bling | last post by:
Hi Everyone, This Saturday the stage was set. The problem simply could not go on existing -- it had to be solved. Many hours, articles, compilations and frustrations later I still did not find...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.