Click here to Skip to main content
15,911,132 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to show the list in datasheet view and be able to update the Type attribute value of View node with xpath. However, when I try to update the view using setviewxml it is not getting updated.

Any help is greatly appreciated.
C#
XsltListViewWebPart myWebPart = (XsltListViewWebPart)oWebpart;

SPView doclibview = view;
Guid oGuid = new Guid(myWebPart.ViewGuid);


SPView oWebPartView = list.Views[oGuid];


oWebPartView.ViewFields.DeleteAll();

foreach (string strField in doclibview.ViewFields)
{
    oWebPartView.ViewFields.Add(strField);
}
string strloadxml = oWebPartView.GetViewXml();

XmlDocument doc = new XmlDocument();
doc.LoadXml(strloadxml);

XmlNode node = doc.SelectSingleNode("/View");
node.Attributes["Type"].Value = "Grid";

string resxml = doc.InnerXml.ToString();
oWebPartView.SetViewXml(resxml);

oWebPartView.Update();
Posted
Updated 24-Feb-12 1:14am
v2
Comments
Slacker007 24-Feb-12 7:15am    
Edits: moved text above code block and reformatted code block.
[no name] 24-Feb-12 12:44pm    
What version, 2007 or 2010? What is the environment? A webpart, application page, server app? Giving more details will help in getting an answer.
samathaboini 25-Feb-12 3:54am    
hi Mark I am working on sharepoint 2010.I am writing the above code in Visual webpart.Thanks for your reply

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900