Microsoft KB Archive/309338

= The Attributes property of a ListItem control only works within an HtmlSelect control =

Article ID: 309338

Article Last Modified on 1/26/2004

-

APPLIES TO


 * Microsoft ASP.NET 1.0
 * Microsoft ASP.NET 1.1

-



This article was previously published under Q309338



SYMPTOMS
When you use the RadioButton or DropDownList control, if you try to place a key-value pair in the ListItem control, the key-value pairs are not written to the result page.

For example, the following RadioButtonList code  1 

-or-

RadioButtonList1.Items[0].Attributes.Add(&quot;key&quot;, &quot;k1&quot;); only returns the following output:  1 Similarly, the following DropDownList code  1  only returns the following output: 1 The &quot;Key=k1&quot; is not rendered.



CAUSE
The ListItem control has a property Attributes of type AttributeCollection. When the ListItem control is inside a RadioButtonList control or a DropDownList control, key-value pairs that you assign to the Attributes property of the ListItem control (either programmatically or declaratively) are not rendered.



RESOLUTION
To work around this problem in the RadioButtonList control, use a group of HtmlInputRadioButton controls. For example:  To work around this problem in the DropDownList control, use the HtmlSelect control. For example:  <option value=&quot;v1&quot; id=&quot;ID1&quot; key=&quot;k1&quot;>1

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

MORE INFORMATION
In the &quot;Resolution&quot; section of this article, the HtmlSelect control was used to show how to implement expando attributes as a workaround for using the DropDownList control. While both classes do make use of the ListItem class internally, they support expando attributes differently. The HtmlSelect control does support using expando attributes because its programming model is more HTML-centric. However, supporting expando attributes with the DropDownList control is more involved than just rendering the attributes themselves. For example, you cannot use data-binding to support attributes with the DropDownList control.

Additional query words: kbreadme

Keywords: kbreadme kbprb kbservercontrols KB309338

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.