Using the ViewState within the SelectMethod of a ObjectDataSource

by Pieter Brinkman 3. June 2009 07:32

By default it is not possible to use the ViewState within methods of a ObjectDataSource. Because the DataSource doesn't run within the current page instance, it just fires the method that you specified.

You can set the page instance for the DataSourceby setting the ObjectInstance property in the ObjectCreating event of the DataSource.

[code:html]

<asp:ObjectDataSource ID="odsListing" runat="server" SelectMethod="getItems" TypeName="YOUR.NAMESPACE" OnObjectCreating="ObjectDataSource_ObjectCreating" DataObjectTypeName="List&lt;Item>">

[/code]

protected void ObjectDataSource_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
{
 e.ObjectInstance = this;
}

Now you can use the ViewState in you DataSourceMethod (getItems() in this example).

 

Tags: , , ,

ASP.Net | Controls

Comments

6/5/2009 6:00:14 AM #

Joost van Schaik

Nice to see that we are running the same kind of blog Wink

Joost van Schaik

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About Me

My name is Pieter Brinkman I am Solution Architect for Sitecore in The Netherlands. My interests are mainly ASP.NET, MSSQL and Content Management Systems.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar

RecentComments

Comment RSS

Most comments