Custom RadioButtonList with Attribute support for ListItem

Discussion in 'ASP .Net Web Controls' started by MattB, Jul 22, 2004.

  1. MattB

    MattB Guest

    I found the listitem class was sealed,

    and can't get tooltips for radio button in
    a radionbuttonlist, apparently this is by design..

    http://support.microsoft.com/default.aspx?scid=kb;en-us;Q309338

    no one said why, I would just write a bunch of radiobutton controls
    but I have I have a Checklist validator

    http://www.dotnetjunkies.com/Article/ECCCD6A6-B312-41CB-87A1-10BB5D641D20.dcik

    and want to continue using it, as I am not sure how to get a group of
    radiobuttons of Checkboxes in to verify one of them is select

    so I wrote the following, all is good except I lose the viewstate of
    the
    selected radiobutton on postback, I am new to custom controls and they
    seem
    very dependant on what which class you are overriding....

    can anyone help, thanks...m@

    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace MY.UI
    {
    /// <summary>
    /// Summary description for TooltipRadioButtonList.
    /// </summary>
    public class TooltipRadioButtonList :
    System.Web.UI.WebControls.RadioButtonList
    {
    protected override void Render(HtmlTextWriter writer)
    {
    //RenderChildren(writer);
    int i = 0;
    foreach (ListItem listItem in Items)
    {
    writer.WriteBeginTag("input");
    writer.WriteAttribute("ID",this.UniqueID+"_"+i );
    writer.WriteAttribute("type", "radio");
    writer.WriteAttribute("name", this.UniqueID);
    writer.WriteAttribute("value", listItem.Value, true);
    listItem.Attributes.Render(writer);
    writer.Write('>');
    writer.WriteEndTag("input");
    writer.WriteBeginTag("label");
    writer.WriteAttribute("for",this.UniqueID+"_"+i );
    listItem.Attributes.Render(writer);
    writer.Write('>');
    HttpUtility.HtmlEncode(listItem.Text, writer);
    writer.WriteEndTag("label");
    if (i < Items.Count-1)
    writer.RenderBeginTag(HtmlTextWriterTag.Br);
    writer.WriteLine();
    i++;
    }
    }
    }
    }
     
    MattB, Jul 22, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick Spiewak
    Replies:
    3
    Views:
    5,152
  2. Mad Scientist Jr
    Replies:
    2
    Views:
    496
    Mad Scientist Jr
    Jun 29, 2004
  3. Jim in Arizona
    Replies:
    7
    Views:
    976
    Badass Scotsman
    Nov 22, 2006
  4. Dan
    Replies:
    2
    Views:
    442
  5. MattB

    Custom RadioButtonList with Attribute support for ListItem

    MattB, Jul 23, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    784
    MattB
    Jul 23, 2004
Loading...

Share This Page