Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Tuesday, March 19, 2013

Create an XSLTListViewWebPart Programatically with Paging



try
            {
                XsltListViewWebPart lvwp = new XsltListViewWebPart();
                SPList library = SPContext.Current.Web.Lists["Tasks"];
                if (library != null)
                {
                    SPContext.Current.Web.AllowUnsafeUpdates = true;

                    // gets custom view
                    SPView view = library.DefaultView;
                    for (int i = 0; i < library.Views.Count; i++)
                    {
                        if (library.Views[i].BaseViewID == "41")
                        {
                            uint rowlimit = 5;
                            view = library.Views[i];
                            view.RowLimit = rowlimit;
                            view.Update();
                            break;
                        }
                    }
                    // Sets properties of webpart
                    lvwp.ListName = library.ID.ToString("B").ToUpper();
                    lvwp.ViewGuid = view.ID.ToString("B").ToUpper();
                    lvwp.XmlDefinition = view.GetViewXml();
                    lvwp.SuppressWebPartChrome = true;
                    this.pnlList.Controls.Add(lvwp);
                }

            }
            catch (Exception Ex)
            {
                Response.Write(Ex.ToString());
            }
        }

No comments:

Post a Comment