Scenario:
I think I mentioned about this one in my previous blogs but I binged and couldn't find anything. So thought of writing about it.
We have seen many powerful controls of sharepoint and one of them is SPDataSource
I am sure you heard about SqlDataSource data source control which represents data in an SQL relational database to data-bound controls. You can use the SqlDataSource control in conjunction with a data-bound control to retrieve data from a relational database and to display, edit, and sort data on a Web page with little or no code.
On the same lines , SPDataSource data source control represents Windows SharePoint Services data to data-bound controls. You can use the control in conjunction with a data-bound control to retrieve data from lists, list items, and Web sites and to display, edit, and modify data with little or no code.
-- Like other data source controls,SPDataSource can also be used in UI and Code behind.
-- Unlike other data source controls, the SPDataSource control is associated with only one view. The GetViewNames method always returns a collection that contains the name of just one data view.
Example:
Here's a quick view to get datasource instance from Announcement List
Code:
var datasource = new SPDataSourceArticle:
{
DataSourceMode = SPDataSourceMode.List,
List = SPContext.Current.Web.Lists["Announcements"]
};
MSDN SPDataSource , SPDataSource every sharepoint developer friend 1 , SPDataSource every sharepoint developer friend 2 , SPdatasource-every-developer-friend , spdatasource-mystery-modes-webs-listoflists , Another very good example
Follow me on Twitter
5 comments:
Do you know if there is a way to filter a SPDATASource on a column that is set to people/groups by [ME]
I can't seem to get it to work.
I think thats possible, u need to get the SPQuery with filtered CAML to return SPListItemCollection items and tie it to ur DataSource
thanks for responding,
I'm a little unsure tho how to do this tho.
Is this something I can do within Designer?
yes u can do it using SPD also.. SPDataSource support SelectParameters ... check this article to get an idea
http://snahta.blogspot.com/2008/09/listid-fix-for-listview-webpart.html
I read the other article, and if If understanding it right.
I can change the listid to list name?
So in my spdatasource I've done this anywhere it had listID. My list name is Category
Name="ListName" DefaultValue="Category"
but when I click on configure datasource, all the options are shaded out.
am I on the right track?
Post a Comment