Account Options

  1. Sign in
Google Groups Home
« Groups Home
Message from discussion A Solution for Rendering Attributes into the Individual Items of a RadioButtonList
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dunno  
View profile  
 More options May 15 2005, 11:20 pm
Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
From: "Dunno" <adrian.lehm...@redox.com>
Date: 15 May 2005 20:20:51 -0700
Local: Sun, May 15 2005 11:20 pm
Subject: A Solution for Rendering Attributes into the Individual Items of a RadioButtonList
It's long been a problem that in some ASP.NET WebControls developers
have not been able to render custom/additional attributes. The
RadioButtonList is one such control. For instance you'd think that you
could add attributes to the individual radio buttons by iterating
through the RadioButtonLists.Items collection as so:

foreach(ListItem item in rbl.Items)
{
   item.Attributes.Add("custom", "custom");

}

No good. They attributes just don't render.

The framework RadioButtonList implements the IRederInfoUser interface.
I found that creating a custom RadioButtonList which derives from the
framework one and also implements this interface can provider a
solution to this problem.

The only method that needs to be implemented is the RenderItem method.
This method is responsible for rendering the individual radio buttons
in the list. Example implementation below.

public class CustomRadioButtonList : RadioButtonList, IRepeatInfoUser
{
        void IRepeatInfoUser.RenderItem(ListItemType itemType, int
repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
{
                RadioButton radioButton = new RadioButton();
                radioButton.Page = this.Page;
                radioButton.GroupName = this.UniqueID;
                radioButton.ID = this.ClientID + "_" + repeatIndex.ToString();
                radioButton.Text = this.Items[repeatIndex].Text;
                radioButton.Attributes["value"] = this.Items[repeatIndex].Value;
                radioButton.Checked = this.Items[repeatIndex].Selected;
                radioButton.TextAlign = this.TextAlign;
                radioButton.AutoPostBack = this.AutoPostBack;
                radioButton.TabIndex = this.TabIndex;
                radioButton.Enabled = this.Enabled;

                // Add custom attributes here.
                writer.AddAttribute("custom", "custom");

                radioButton.RenderControl(writer);
        }

}

It may not be the most elegant way around this problem but it has
worked for me.

Happy Coding.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.