.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Code Snippets >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

sharepoint 2010 create XsltListView WebPart programatically

Posted By:Sagar Pardeshi       Posted Date: November 25, 2013    Points: 40    Category: SharePoint    URL: http://www.dotnetspark.com  

In mosss 2007 we user ListView WebPart to display the List item but in sharepoint 2010 explore XsltListView WebPart display the List item

 using (SPSite site = new SPSite(SPContext.Current.Web.Url.ToString()))
                using (SPWeb web = site.OpenWeb())
                    SPList list = web.Lists["Tracker"];
                    XsltListViewWebPart XsltListViewWebPart1 = new XsltListViewWebPart();
                    XsltListViewWebPart1.ListId = list.ID;
                    SPView lstview = list.DefaultView;
                    XsltListViewWebPart1.Toolbar = "";
                    StringBuilder xml = new StringBuilder();
                    xml.Append("<View Name='{" + list.DefaultView.ID.ToString("B").ToString().ToUpperInvariant() + "}' TabularView='FALSE' MobileView='TRUE' Type='HTML'  Hidden='TRUE' DisplayName='' Url='" + Request.Url.ToString() + "' Level='1' BaseViewID='1' ContentTypeID='0x' ImageUrl='/_layouts/images/generic.png'>");
                    xml.Append("<Query><OrderBy><FieldRef Name='ID'/></OrderBy></Query>");
                    xml.Append("<ViewFields> <FieldRef Name='LinkTitle'/><FieldRef Name='Edit'/><FieldRef Name='Role'/></ViewFields>");
                    xml.Append("<RowLimit Paged='TRUE'>30</RowLimit>");
                    xml.Append("<Aggregations Value='Off'/>");
                    xml.Append("<Toolbar Type='Freeform'/></View>");
                    XsltListViewWebPart1.AllowEdit = true;
                    XsltListViewWebPart1.AllowClose = false;
                    XsltListViewWebPart1.AllowConnect = false;
                    XsltListViewWebPart1.AllowHide = false;
                    XsltListViewWebPart1.AllowMinimize = false;
                    XsltListViewWebPart1.AllowZoneChange = false;
                    XsltListViewWebPart1.ChromeType = PartChromeType.None;

                    XsltListViewWebPart1.XmlDefinition = xml.ToString();
                    XsltListViewWebPart1.AsyncRefresh = true;
                    XsltListViewWebPart1.ShowToolbarWithRibbon = true;
                    XsltListViewWebPart1.ExportMode = WebPartExportMode.All;



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend