views:

599

answers:

3

I am trying to create a custom control that inherits from DropDownList.

What I need is to add a new property to a ListItem(within Item collection).

<cc1:MyDropDownList ID="MyDropDownList1" runat="server">   
   <asp:ListItem myProperty="true" text="sometext" ... />                     

</cc1: MyDropDownList>

How can I do that?

+1  A: 

try here for a good video on how to extend server side asp.net controls

Konstantinos
+3  A: 

Even if you inherit from the DropDownList you cannot add this property because you have to add it to the ListItem control.
But the problem is that ListItem class is sealed so you cannot inherit from it.

Marwan Aouida
Yes, I know that it sealed...But what can I do?Any workaround?
markiz
A: 

Can you extend the capabilities client-side with jQuery?

David Robbins
Well, I am not familiar with JQuery :(
markiz
I need this property to "signal" RenderContents to render specific item in a specific way.Sure I can do this by passing this flag in Text property, but this is not clean.
markiz
Without seeing, code I can offer a limited suggestion of creating a structure to hold your data - value, description, variable text - and pass that to the client. Create a javascript function that responds to the click, receives the value, perform a lookup, then act upon the variable text / "flag" you want to pass. If you need to post back, update a hidden field with the "flag" and read it on the server.
David Robbins
Re-thinking last bit of my comment concerning the hidden field. Postback as usual, then respond to the SelectedItem on the server. Again, that's if you MUST postback.
David Robbins
I should have explain what I am trying to do.I want extend dropdownlist with an option to disable an item. By disable I mean preventing it to be selected and clicked. I plan to do so by adding <optgroup> in overrided RenderContents of my new control.So, I want items to have a property "Disabled" that I can set on design/run time and then, in RenderContents, add the tag to the right item.
markiz