Hi chan, I am facing similar problem.I want to add a dropdown into the webpart.I tried it through enum,but could not figure out how to add items into enum dynamically.Could you please share your approach with me. Some code example would be really benefecial.
I believe that there is a way of doing this, but is not that simple...
You can dinamicaly generate & compile code using CodeDOM. You can use CodeDOM to generate anykind of code you want. You can use the classes in the System.CodeDom namespace to create all sort of code.
This means that you can actually write code that will create an enum, at runtime.
No I havn't find a way to add items into enum dynamically but I solve my problem by creating a custom tool part that inherite Microsoft.SharePoint.WebPartPages.ToolPart. There is article about that in MSDN but i dont have the url on hand.
The key is in your custom tool part, you override the RenderToolPart method, from there you can output any html code to the HtmlTextWriter. For me, I just output a select element in my code.
Because I am writing a web part for SharePoint. To define a custom property that will render as a dropdown list in tool pane, I need the variable in a type of enum. Since the number of choice is retrieve at run time, that's why I am asking how to generate dynamic enum.
Anyways, I move one step further to create a custom toolpane and override the rendering method to draw a dropdown list by myself. Problem solved. (not the dynamic enum, but my web part problem)
But I also interested in how to having a dynamic enum, thanks for aghiondea's info but it really a pain.
Hi Chan, Thanks for the reply.Your help was really useful.I have created a dropdown by overriding Gettoolpart method.But now i am facing problem how to get values from dropdown.I am successful in getting value of textbox,but still facing problem with dropdown.
Can I dynamic add item to enum
Dave Waterworth
I am facing similar problem.I want to add a dropdown into the webpart.I tried it through enum,but could not figure out how to add items into enum dynamically.Could you please share your approach with me.
Some code example would be really benefecial.
Thanks
Amit
Nik Ivancic
I believe that there is a way of doing this, but is not that simple...
You can dinamicaly generate & compile code using CodeDOM. You can use CodeDOM to generate anykind of code you want. You can use the classes in the System.CodeDom namespace to create all sort of code.
This means that you can actually write code that will create an enum, at runtime.
More info: http://blogs.msdn.com/bclteam/archive/2005/03/15/396348.aspx and on MSDN.
However, I don't know if this is worth "the pain".
William Bartholomew
Hi Amit,
No I havn't find a way to add items into enum dynamically but I solve my problem by creating a custom tool part that inherite Microsoft.SharePoint.WebPartPages.ToolPart. There is article about that in MSDN but i dont have the url on hand.
The key is in your custom tool part, you override the RenderToolPart method, from there you can output any html code to the HtmlTextWriter. For me, I just output a select element in my code.
Jason.
Leandro Rodrigues
Hi, I solved my problem.
Because I am writing a web part for SharePoint. To define a custom property that will render as a dropdown list in tool pane, I need the variable in a type of enum. Since the number of choice is retrieve at run time, that's why I am asking how to generate dynamic enum.
Anyways, I move one step further to create a custom toolpane and override the rendering method to draw a dropdown list by myself.
Problem solved. (not the dynamic enum, but my web part problem)
But I also interested in how to having a dynamic enum, thanks for aghiondea's info but it really a pain.
dreameR.78
Thanks for the reply.Your help was really useful.I have created a dropdown by overriding Gettoolpart method.But now i am facing problem how to get values from dropdown.I am successful in getting value of textbox,but still facing problem with dropdown.
Thanks.
Amit
Antediluvia
xshua
Hi,
I had problem in rendering controls in custom tool pane. The questin is, How to retrieve values from the custom tool part class
1. For example, i am creating a dropdown list control in custom tool part and how to retrieve the value selced in that
2. If i am creating a gridview control in custom tool part, how to make use of the whole gridview in the webpart class
Please help me in this!!!
Thanks in Advance,
Vimal.
RobGiorgi
sunny123
Hi,
I am also facing the same problem. I am also writing custom webpart for sharepoint. Can you help on this.