Click here to Skip to main content
15,887,485 members
Articles / Web Development / ASP.NET

A Simple and Extensible Radio Button Style GridView

Rate me:
Please Sign up or sign in to vote.
2.00/5 (1 vote)
25 Apr 2009CPOL5 min read 40.8K   583   3  
An article on describing how to create a radio button style GridView
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace RadioButtonGridView
{
    public class RadioButtonTemplate : ITemplate
    {
        public RadioButtonTemplate()
        {
        }

        public void InstantiateIn(Control container)
        {
            RadioButtonEx radioButton = new RadioButtonEx()
            {
                ID = _radioButtonID,
                GroupName = _radioButtonGroupName,
                AutoPostBack = _radioButtonAutoPostBack
            };

            container.Controls.Add(radioButton);
        }

        #region Public Properties

        // ============================================

        private Boolean _radioButtonAutoPostBack = true;

        /// <summary>
        /// Ges or sets the flag to determine whether the internal radio button should automatically post back.
        /// </summary>
        public Boolean RadioButtonAutoPostBack
        {
            get
            {
                return _radioButtonAutoPostBack;
            }
            set
            {
                _radioButtonAutoPostBack = value;
            }
        }

        // ==========================================

        private String _radioButtonGroupName;

        /// <summary>
        /// Gets or sets the internal radio button group name.
        /// </summary>
        public String RadioButtonGroupName
        {
            get
            {
                return _radioButtonGroupName;
            }
            set
            {
                _radioButtonGroupName = value;
            }
        }

        // ====================================

        private String _radioButtonID;

        /// <summary>
        /// Gets or sets the internal radio button ID.
        /// Note that the UniqueID of each radio button composed by NamingContainer UniqueID and
        /// itself ID.
        /// </summary>
        public String RadioButtonID
        {
            get
            {
                return _radioButtonID;
            }
            set
            {
                _radioButtonID = value;
            }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer ChinaSoft
China China
Fighting for life.

Comments and Discussions