***********************************************************************
* 版权声明
* 此文章为ocean所有,版权归ocean所有,任何网
* 站和 媒体转载必须包含此段声明,否则将视为侵权,作
* 者将保留一切权力。此声明为此文章中不可或缺的一部分。
* 作者网名:ocean
* http://sps.oceanstudio.net
* 作者blog:博客园,http://www.cnblogs.com/ocean
* Ocean's blog,http://www.oceanstudio.net/sps/blog
* 此文章发表时间:2005年3月17日
* 作者blog:博客园,http://www.cnblogs.com/ocean
* Ocean's blog,http://www.oceanstudio.net/sps/blog
* 此文章发表时间:2005年3月17日
************************************************************************
如何能够在自定义WebPart中的菜单呢?达到下图的效果:
我还专门提供了一个示例,代码可以点击此处下载。 这个示例本身不是我写的,我只是对其进行了一下包装。
本来还作了一个演示示例, 但可惜自定义菜单后,匿名用户是无法访问的,所以只能是验证用户才可以。
同时你可以从 http://www.oceanstudio.net/sps/Lists/webpart/AllItems.aspx 查看其它的WebPart。
如何来做呢?在WebPart中我们需要重载CreateWebPartMenu()函数,这个函数是用来生成WebPart的下拉菜单的,其中在WebPart中有一个WebPartMenu对象,这个对象就是WebPart的菜单对象。通过this.WebPartMenu.MenuItems就可以得到所有的菜单项目,当然菜单是可以好多级的。生成菜单通过new MenuItem(),添加一个菜单只要通过MenuItems.Add方法即可。我们还可以为菜单添加客户端或者服务端事件。还可以标记菜单,比如那个删除菜单前面打了一个勾,这是通过MenuItem.Checked = true来实现的。废话不多说了,代码如下:




































欢迎访问海洋工作室( http://sps.oceanstudio.net )