A combination of bullet-list and radio-button list controls : RadioButtonList « ASP.net Controls « ASP.NET Tutorial






<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 
    Inherits="Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Bullets & Radios</title>
</head>
<body>
    <div id="pageContent">
        <form id="form1" runat="server">
            <asp:RadioButtonList ID="BulletOptions" runat="server" AutoPostBack="True" 
                OnSelectedIndexChanged="BulletOptions_SelectedIndexChanged" 
                RepeatColumns="3" 
                RepeatDirection="Horizontal" />
            <hr />
            <asp:BulletedList ID="BulletedList1" runat="server" 
                BulletImageUrl="/core35/images/bullet.gif" />
        </form>
    </div>
</body>
</html>

File: Default.aspx.cs

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Data : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
      FillOptions();
      FillCountries();
    }
  }

  protected void FillOptions()
  {
    BulletOptions.DataSource = Enum.GetValues(typeof(BulletStyle));
    BulletOptions.SelectedIndex = 0;
    BulletOptions.DataBind();
  }

  protected void FillCountries()
  {
    string connString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
    string cmdText = "SELECT DISTINCT country FROM customers";

    DataTable data = new DataTable();
    SqlDataAdapter adapter = new SqlDataAdapter(cmdText, connString);
    adapter.Fill(data);

    BulletedList1.DataSource = data;
    BulletedList1.DataTextField = "country";
    BulletedList1.DataBind();
  }

  protected void BulletOptions_SelectedIndexChanged(object sender, EventArgs e)
  {
    BulletStyle style = (BulletStyle) Enum.Parse(typeof(BulletStyle), BulletOptions.SelectedValue);
    BulletedList1.BulletStyle = style;
  }
}








3.14.RadioButtonList
3.14.1.Get selected item index from asp:RadioButtonList (VB.net)
3.14.2.Data binding with the RadioButtonList Control
3.14.3.A combination of bullet-list and radio-button list controls