简体   繁体   English

SharePoint 2010中WebPart属性的下拉列表

[英]Dropdown in webpart property in sharepoint 2010

Hi I am creating a visualwebpart in sharepoint 2010 with some webpart property. 嗨,我正在使用某些WebPart属性在sharepoint 2010中创建visualwebpart。 In webpart property I am trying to creating a dropdown using enum. 在webpart属性中,我试图使用枚举创建一个下拉列表。

public enum FileTypeSupport
    {            
        OnlyImage,
        OnlyVideo,
        ImageAndVideo
    };
    public static FileTypeSupport fileType;

    [Personalizable(PersonalizationScope.Shared),
    Category("Caustom Property"),
    WebBrowsable(true),
    WebDisplayName("File Type Support"),
    Description("Specify the number of image which will show at a time")]
    public FileTypeSupport SelectedfileType
    {
        get { return fileType; }
        set { fileType = value; }
    }

This is working fine but my requirement is to dropdown of {Only Image, Only Video,Image And Video}, ie with some space(OnlyImage-->Only Image), but it is not supporting in enum. 这工作正常,但我的要求是下拉{仅图像,仅视频,图像和视频},即具有一定的空间(仅图像->仅图像),但不支持枚举。 Can anyone tell me how can I fullfill that requirement. 谁能告诉我如何满足这一要求。

IF I understand you right here you want to display "Only Image" when "OnlyImage" is selected? 如果我了解您在这里,您想在选择“ OnlyImage”时显示“ Only Image”吗?

Then you have to possibilities: Posibillity ONE: Use a 然后,您将有可能:可能性一:使用

public Dictionary<enum,string> SelectedFileType {

}

Where the enum contains: (FileTypeSupport.OnlyImage, "Only Image") 枚举所在的位置: (FileTypeSupport.OnlyImage, "Only Image")

Possibility TWO: If you have exact rules you can modify the getter and setter: 可能性二:如果您有确切的规则,则可以修改getter和setter:

public string SelectedfileType
{
get { return Regex.Replace(fileType.ToString(), "([a-z])([A-Z])", "$1 $2")); }
set { fileType=enum.Parse(typeOf(FileTypeSupport),value.Replace(" ","");
}

I stole the Getter from this SO answer . 我从这个答案中偷走了吸气剂。 You can also find other answers there without regex which have a better performance. 您也可以在没有正则表达式的情况下找到其他具有更好性能的答案。 (But performance should not really be a problem as you use SharePoint) (但是,在使用SharePoint时,性能应该不是真正的问题)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM