title: Extend Content Query Web Part via Code
body: <p>I'm trying to understand the mechanism to extend the cqwp via code.</p>
  
  <p>It may be hard to believe but I couldn't find a single article to create a web part inherited from <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.webcontrols.contentbyquerywebpart.aspx" rel="nofollow">content by query web part</a>.</p>
  
  <p>What I need to do, is to type the listname in the web part properties. Then all the groupings, sorting and the query will be implemented via code, that is in the extended web part.</p>
  
  <p>I've read waldek's posts but they are a bit advanced to use as a cheat sheet.</p>
  
  <p>Msdn's samples show the customization of itemstyle and setting queryoverride over the webpart properties toolbar. I need to set it via code. </p>
  
  <p><strong>Note</strong>:If that's not the way to customize cqwp, let me know. My purpose is to put the wp in the masterpage and set the listname and wait for the results to show(:</p>
  
  <p>I've tried to set the listguid and queryoverride via code through OnInit and ModifyXsltArgument methods seperately. Nothing returned, and when I export the wp, the listguid and queryoverride seems not set.</p>
  
  <p>I'm sure I'm doing something basic wrong, so I'd appreciate your help.
  Thanks in advance..</p>