Aidan Garnish
MOSS 2007 and other Microsoft technologies

Web part custom property - dropdown list

December 19, 2007 09:40 by aidan

It isn't immediately obvious how to include a drop down list as a custom property on a web part. To do this you simply use an enum.

Eg.

//create enum

public enum ProductByEnum

{Type = 0,

Brand,

Chemistry};

//create get/set for the property

protected ProductByEnum productsBy;

[Personalizable(PersonalizationScope.User),WebBrowsable, WebDisplayName("Products By"),WebDescription("Use this property to change web part grouping")]public ProductByEnum ProductsBy

{

get { return productsBy; }

set { productsBy = value; }

}

A dropdown list will now appear in the miscellaneous section of your web part custom properties containing the enum values.


Currently rated 3.7 by 3 people

  • Currently 3.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Comments

December 28. 2007 17:09

How can do for that ProductByEnum to be variable.

The DropDown generated like that to be dynamic.

Thank... Jorge

Jorge Sanchez

December 28. 2007 22:22

Hi Jorge,
I'm not 100% sure what you are asking. Do you want to populate the drop down dynamically from a database table? I have not done this but you could try to do this by populating the values of your enum from the values in the database. Is that what you want to do or are you asking something else entirely?

aidan

February 15. 2008 09:23

can i use dot net control within a a web part?

sanju

April 17. 2008 09:34

i want dropdown list to populate list values and appear in the miscellaneous section of your web part custom properties

Rock

April 30. 2008 10:05

without using an enum, i need to have a dropdown list in the custom properties wherein it gets values from Custom list.
whenever i add values to the list it needs to be reflected on the properties list pane.

Rock

May 28. 2008 12:10

i want that the enum created should have values as the names of all the lists created in the site. How to do this????

tejas

August 20. 2008 16:22

Hi there.
I tried many ways but "ProductsBy" always apear as a normal text box in the property pane.

Any idea ?
Thx

Pascal Bergeron

August 20. 2008 17:49

Can you post your code?

aidan

August 20. 2008 18:02

The code is in a UserControl.Ascx added to sharepoint with SmartPart v1.3

You will recognize the code Smile

using System;
using System.IO;
using System.Net;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using System.ComponentModel;

public partial class AnaDateRangeExport : System.Web.UI.UserControl
{
//create enum

public enum ProductByEnum
{
Type = 0,

Brand,

Chemistry
};

//create get/set for the property

protected ProductByEnum productsBy;

[Personalizable(PersonalizationScope.User), WebBrowsable, WebDisplayName("Products By"), WebDescription("Use this property to change web part grouping")]
public ProductByEnum ProductsBy
{

get { return productsBy; }

set { productsBy = value; }

}

Pascal Bergeron

August 20. 2008 18:26

I don't think this code will work as part of an ascx. Try using it as part of a web part instead.

aidan

December 22. 2008 14:01

also have a look at this examnple: laymensterm.blogspot.com/.../...own-from-enum.html

Dusty

Add comment


 

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

January 6. 2009 14:23