SPWeb WssSite = SPControl.GetContextWeb(Context); 
  SPList list = WssSite.Lists["--List Name--"];
  WssSite.AllowUnsafeUpdates=true;
  DataViewWebPart DVWebPart = new DataViewWebPart();
  
  DVWebPart.ZoneID = "ZoneForMenu";
  DVWebPart.Width="130";
  DVWebPart.Title="DataView Web Part";
  DVWebPart.FrameType= FrameType.None;
  DVWebPart.ListName = list.ID.ToString("B").ToUpper();
  DVWebPart.Description = list.ID.ToString("B").ToUpper();

  //Optional:
  //DVWebPart.Xsl="xsl code here";
  //DVWebPart.DataQuery="DataQuery Code Here";

  SPWebPartCollection webPartCollection = WssSite.GetWebPartCollection(Request.ServerVariables["URL"] , Storage.Shared);
  int WebPartCount=0;
  
  if (webPartCollection != null)
  {
    webPartCollection.Web.AllowUnsafeUpdates=true;
    webPartCollection.Add(DVWebPart);
    
  }
  else
  {
   //Response.Write("webPartCollection is null ");
  }
  
   
  WssSite.AllowUnsafeUpdates=false;
   
     //Cleanup:
  
  WssSite.Dispose();
  WssSite  = null;
  webPartCollection=null;
  DVWebPart.Dispose();
  DVWebPart=null;

  //refresh the page to see the new DataViewWebPart.
  Response.Redirect(Request.ServerVariables["URL"]);

相关文章:

  • 2022-12-23
  • 2022-03-07
  • 2021-06-13
  • 2021-06-26
  • 2021-12-10
  • 2021-08-26
  • 2021-09-28
  • 2021-09-22
猜你喜欢
  • 2022-12-23
  • 2021-07-03
  • 2021-05-22
  • 2021-10-16
  • 2021-10-22
  • 2021-09-08
  • 2022-01-15
相关资源
相似解决方案