Using the ViewState within the SelectMethod of a ObjectDataSource

VN:F [1.9.22_1171]
Rating: 10.0/10 (2 votes cast)

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.


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



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


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

VN:F [1.9.22_1171]
Rating: 10.0/10 (2 votes cast)
Using the ViewState within the SelectMethod of a ObjectDataSource, 10.0 out of 10 based on 2 ratings
Using the ViewState within the SelectMethod of a ObjectDataSource Pieter Brinkman avatarAuthor: Pieter Brinkman ()

Pieter is Technical Marketing Manager for Sitecore Netherlands and owner of Gaatverweg.nl. He has more than ten years experience with software developing in multiple programming languages and with different Content Management Systems. Before joining Sitecore Pieter was a lead developer for multiple Sitecore and .Net projects, he joined Sitecore in 2011 as an Solution Architect in The Netherlands, after two years as an Solution Architect he joined the Technical Marketing department. In the role as Techinical Marketing Manager he is responsible for the Global MVP program and the Sitecore technical branding strategy. You can follow Pieter on twitter: @pieterbrink123 or Google+

Using the ViewState within the SelectMethod of a ObjectDataSource WebsiteUsing the ViewState within the SelectMethod of a ObjectDataSource TwitterUsing the ViewState within the SelectMethod of a ObjectDataSource Google PlusUsing the ViewState within the SelectMethod of a ObjectDataSource Linkedin

Related posts

Asp.Net: keyboard sort items
LINQ: Creating a if statement in Linq query
Daily Tip: Sitecore caching sliding and absolute
Coded field datasources in Sitecore

One Response to Using the ViewState within the SelectMethod of a ObjectDataSource

Comments
Tweets
Pingbacks
  • Joost van Schaik

    Nice to see that we are running the same kind of blog ;-)

    Click on a tab to select how you'd like to leave your comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>