How can I rendering select list item with added attributes?
-
I can add an attribute to each option in a drop-down list, using the System.Web.UI.WebControls.ListBox.Items.Item(ItemIndex).Attributes.Add() method, but they are ignored when the list is rendered to the web-page. How can I render them? I'm currently adding the controls as childern to a span element, and then using the span.RenderControl(output) method to do the heavy lifting. Is there a method that I can override that specifically renders the options?
-
I can add an attribute to each option in a drop-down list, using the System.Web.UI.WebControls.ListBox.Items.Item(ItemIndex).Attributes.Add() method, but they are ignored when the list is rendered to the web-page. How can I render them? I'm currently adding the controls as childern to a span element, and then using the span.RenderControl(output) method to do the heavy lifting. Is there a method that I can override that specifically renders the options?
No this will not work with combo box or Radio button list. You can use Javascript to do apply. Also what attribute you want to add on ListItem since there is no JS event like onchnage , onclick for element in HTML all events are for element Nobody is perfect i'm Nobody
-
No this will not work with combo box or Radio button list. You can use Javascript to do apply. Also what attribute you want to add on ListItem since there is no JS event like onchnage , onclick for element in HTML all events are for element Nobody is perfect i'm Nobody
In JavaScript and HTML, I created an list of options for a select list that had a UserProperties opbject, in which I created a "list" of arbitrary sub-attributes, similar to the style attributes. Then I added a function that could get this information from the selected option. This all worked well for storing additional values in the options, which could be referenced when the select's onSelect/OnChange event fired. Now, I want to include this capability in my component. I created a property that allows me to manage the UserProperties as an arrary. Then when the select list's children are created, I use the ListItem attribute.add method to push the array value into the option. Unfortunately, Mircrosoft let you add the attribute, but doesn't render tham. :( I could pass the array to the page, and then hava javascript push the values into the options, but that would be redundant. I was hoping that there was a render for the option that I could override, and then create the tag strings myself. In the past, before linking all of my sub-components together as childern under a main span element and then letting the render method do all of the work, I was explictly was calling the render for each sub-component explicity, and adding 'little bits' of hard coded html to the output stream to implement to new features I wanted in my component. Now that the sub-components are all linked up as childern of the main span, I need some way to get the render to call my render method for the options instead of the built-in one. It seems to me that if good modular programming practices were employed that the option rendering would be a seperate routine from the select rendering routine, and that the option rendering routine would be overridiable. The online help says "Gets a collection of attribute name and value pairs for the ListItem that are not directly supported by the class." But then goes on to say "Use the Attributes collection to manage the attribute name and value pairs declared in the opening and closing tags of the ListItem, but not directly supported by the class. You can programmatically add or remove attributes to the collection." When I look at the Attributes collection, there is a render method, but its not clear to me how I could call get my code in to execute it. Any ideas? Thank you